summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2014-02-12 15:49:31 +0200
committerLeif Åstrand <leif@vaadin.com>2014-02-12 15:49:49 +0200
commit42f2387165471d08bbd24d4c3ae4a271d2cda4c5 (patch)
tree4418a7610edf326d308f65ee0d79d4d09c341a93 /uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
parent50381a619458017d69b044435a22fae457a5d4c1 (diff)
parent40e07d0172532ebf5750b8c2aab5ec892e42cdab (diff)
downloadvaadin-framework-42f2387165471d08bbd24d4c3ae4a271d2cda4c5.tar.gz
vaadin-framework-42f2387165471d08bbd24d4c3ae4a271d2cda4c5.zip
Merge remote-tracking branch 'origin/master' into grid
Change-Id: I8f1f412eeb450688bba58b715eba6db9e4ae43ae
Diffstat (limited to 'uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java')
-rw-r--r--uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java60
1 files changed, 53 insertions, 7 deletions
diff --git a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
index d7b7cd050f..55a2b80918 100644
--- a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
+++ b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
@@ -28,9 +28,13 @@ import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
+import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.HasInputDevices;
+import org.openqa.selenium.interactions.Keyboard;
+import org.openqa.selenium.interactions.Mouse;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
@@ -74,6 +78,11 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
*/
private static final int SCREENSHOT_WIDTH = 1500;
+ /**
+ * Timeout used by the TB grid
+ */
+ private static final int BROWSER_TIMEOUT_IN_MS = 30 * 1000;
+
private DesiredCapabilities desiredCapabilities;
private boolean debug = false;
@@ -270,6 +279,21 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
}
/**
+ * Uses JavaScript to determine the currently focused element.
+ *
+ * @return Focused element or null
+ */
+ protected WebElement getFocusedElement() {
+ Object focusedElement = ((JavascriptExecutor) getDriver())
+ .executeScript("return document.activeElement");
+ if (null != focusedElement) {
+ return (WebElement) focusedElement;
+ } else {
+ return null;
+ }
+ }
+
+ /**
* Find a Vaadin element based on its id given using Component.setId
*
* @param id
@@ -641,17 +665,21 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
}
/**
- * Helper method for sleeping X ms in a test. Catches and ignores
- * InterruptedExceptions
+ * Sleeps for the given number of ms but ensures that the browser connection
+ * does not time out.
*
* @param timeoutMillis
* Number of ms to wait
+ * @throws InterruptedException
*/
- protected void sleep(int timeoutMillis) {
- try {
- Thread.sleep(timeoutMillis);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
+ protected void sleep(int timeoutMillis) throws InterruptedException {
+ while (timeoutMillis > 0) {
+ int d = Math.min(BROWSER_TIMEOUT_IN_MS, timeoutMillis);
+ Thread.sleep(d);
+ timeoutMillis -= d;
+
+ // Do something to keep the connection alive
+ getDriver().getTitle();
}
}
@@ -882,4 +910,22 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
}
+ /**
+ * Returns the mouse object for doing mouse commands
+ *
+ * @return Returns the mouse
+ */
+ public Mouse getMouse() {
+ return ((HasInputDevices) getDriver()).getMouse();
+ }
+
+ /**
+ * Returns the keyboard object for controlling keyboard events
+ *
+ * @return Return the keyboard
+ */
+ public Keyboard getKeyboard() {
+ return ((HasInputDevices) getDriver()).getKeyboard();
+ }
+
}