aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenri Sara <henri.sara@gmail.com>2017-02-13 16:48:15 +0200
committerGitHub <noreply@github.com>2017-02-13 16:48:15 +0200
commit4c61090f2da4109f8455fd03df9c876a0286fc07 (patch)
tree97ffdbd4305c48fc7a018e85ef29e6ea7ea29958
parente34b45eb4c096cf16219fa1f71bab8ab55947d5c (diff)
downloadvaadin-framework-4c61090f2da4109f8455fd03df9c876a0286fc07.tar.gz
vaadin-framework-4c61090f2da4109f8455fd03df9c876a0286fc07.zip
Add workarounds for Firefox in context click tests (#8547)
-rw-r--r--uitest-common/src/main/java/com/vaadin/tests/tb3/AbstractTB3Test.java11
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/checkbox/CheckboxContextClickTest.java5
-rw-r--r--uitest/src/test/java/com/vaadin/tests/contextclick/AbstractContextClickTest.java22
-rw-r--r--uitest/src/test/java/com/vaadin/tests/contextclick/GridContextClickTest.java2
4 files changed, 32 insertions, 8 deletions
diff --git a/uitest-common/src/main/java/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest-common/src/main/java/com/vaadin/tests/tb3/AbstractTB3Test.java
index 6a82492da5..0322d76949 100644
--- a/uitest-common/src/main/java/com/vaadin/tests/tb3/AbstractTB3Test.java
+++ b/uitest-common/src/main/java/com/vaadin/tests/tb3/AbstractTB3Test.java
@@ -1012,6 +1012,17 @@ public abstract class AbstractTB3Test extends ParallelTest {
}
}
+ protected void contextClickElement(WebElement element) {
+ if (BrowserUtil.isFirefox(getDesiredCapabilities())) {
+ // Workaround for Selenium/TB and Firefox 45 issue
+ getCommandExecutor().executeScript(
+ "var ev = document.createEvent('HTMLEvents'); ev.initEvent('contextmenu', true, false); arguments[0].dispatchEvent(ev);",
+ element);
+ } else {
+ new Actions(getDriver()).contextClick(element).perform();
+ }
+ }
+
protected boolean isLoadingIndicatorVisible() {
WebElement loadingIndicator = findElement(
By.className("v-loading-indicator"));
diff --git a/uitest/src/test/java/com/vaadin/tests/components/checkbox/CheckboxContextClickTest.java b/uitest/src/test/java/com/vaadin/tests/components/checkbox/CheckboxContextClickTest.java
index 1842d9659b..0c44732ee4 100644
--- a/uitest/src/test/java/com/vaadin/tests/components/checkbox/CheckboxContextClickTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/components/checkbox/CheckboxContextClickTest.java
@@ -20,7 +20,6 @@ import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.WebElement;
-import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.DesiredCapabilities;
import com.vaadin.testbench.By;
@@ -42,11 +41,11 @@ public class CheckboxContextClickTest extends MultiBrowserTest {
WebElement input = checkbox.findElement(By.xpath("input"));
WebElement label = checkbox.findElement(By.xpath("label"));
- new Actions(getDriver()).contextClick(input).perform();
+ contextClickElement(input);
Assert.assertEquals("1. checkbox context clicked", getLogRow(0));
Assert.assertEquals("checked", checkbox.getValue());
- new Actions(getDriver()).contextClick(label).perform();
+ contextClickElement(label);
Assert.assertEquals("2. checkbox context clicked", getLogRow(0));
Assert.assertEquals("checked", checkbox.getValue());
}
diff --git a/uitest/src/test/java/com/vaadin/tests/contextclick/AbstractContextClickTest.java b/uitest/src/test/java/com/vaadin/tests/contextclick/AbstractContextClickTest.java
index 0eda88863d..8497ec8eed 100644
--- a/uitest/src/test/java/com/vaadin/tests/contextclick/AbstractContextClickTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/contextclick/AbstractContextClickTest.java
@@ -31,6 +31,7 @@ import org.openqa.selenium.remote.DesiredCapabilities;
import com.vaadin.testbench.elements.AbstractComponentElement;
import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.parallel.BrowserUtil;
import com.vaadin.testbench.parallel.TestCategory;
import com.vaadin.tests.tb3.MultiBrowserTest;
@@ -137,13 +138,26 @@ public abstract class AbstractContextClickTest extends MultiBrowserTest {
* @param e
* web element
* @param xCoord
- * x coordinate
+ * x coordinate relative to the top-left corner of the element
* @param yCoord
- * y coordinate
+ * y coordinate relative to the top-left corner of the element
*/
protected void contextClick(WebElement e, int xCoord, int yCoord) {
- new Actions(getDriver()).moveToElement(e, xCoord, yCoord).contextClick()
- .moveByOffset(-5, -5).click().perform();
+ if (BrowserUtil.isFirefox(getDesiredCapabilities())) {
+ // Workaround for Selenium/TB and Firefox 45 issue
+ int x = e.getLocation().getX() + xCoord;
+ int y = e.getLocation().getY() + yCoord;
+ getCommandExecutor().executeScript(
+ "var ev = document.createEvent('MouseEvents'); ev.initMouseEvent('contextmenu', true, true, document.defaultView, 1, arguments[1], arguments[2], arguments[1], arguments[2], false, false, false, false, 2, null); arguments[0].dispatchEvent(ev);",
+ e, x, y);
+ // make sure browser context menu does not block the test
+ getCommandExecutor().executeScript(
+ "var ev = document.createEvent('MouseEvents'); ev.initMouseEvent('click', true, true, document.defaultView, 1, arguments[1]-5, arguments[2]-5, arguments[1]-5, arguments[2]-5, false, false, false, false, 1, null); arguments[0].dispatchEvent(ev);",
+ e, x, y);
+ } else {
+ new Actions(getDriver()).moveToElement(e, xCoord, yCoord)
+ .contextClick().moveByOffset(-5, -5).click().perform();
+ }
}
}
diff --git a/uitest/src/test/java/com/vaadin/tests/contextclick/GridContextClickTest.java b/uitest/src/test/java/com/vaadin/tests/contextclick/GridContextClickTest.java
index 024633b499..2ad0c6a114 100644
--- a/uitest/src/test/java/com/vaadin/tests/contextclick/GridContextClickTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/contextclick/GridContextClickTest.java
@@ -21,8 +21,8 @@ import org.junit.Ignore;
import org.junit.Test;
import org.openqa.selenium.WebElement;
-import com.vaadin.testbench.elements.GridElement;
import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.GridElement;
public class GridContextClickTest extends AbstractContextClickTest {