summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/tb3
diff options
context:
space:
mode:
Diffstat (limited to 'uitest/src/com/vaadin/tests/tb3')
-rw-r--r--uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java125
-rw-r--r--uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java25
-rw-r--r--uitest/src/com/vaadin/tests/tb3/TB3Runner.java37
3 files changed, 159 insertions, 28 deletions
diff --git a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
index 8dd10216d2..1c5fb380ab 100644
--- a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
+++ b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
@@ -16,6 +16,8 @@
package com.vaadin.tests.tb3;
+import static com.vaadin.tests.tb3.TB3Runner.localWebDriverIsUsed;
+
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -24,11 +26,15 @@ import java.net.URL;
import java.util.Collections;
import java.util.List;
-import com.vaadin.testbench.TestBenchElement;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
-import org.openqa.selenium.*;
+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.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.HasInputDevices;
import org.openqa.selenium.interactions.Keyboard;
import org.openqa.selenium.interactions.Mouse;
@@ -45,13 +51,12 @@ import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium;
import com.vaadin.server.LegacyApplication;
import com.vaadin.server.UIProvider;
import com.vaadin.testbench.TestBench;
+import com.vaadin.testbench.TestBenchElement;
import com.vaadin.testbench.TestBenchTestCase;
import com.vaadin.tests.components.AbstractTestUIWithLog;
import com.vaadin.tests.tb3.MultiBrowserTest.Browser;
import com.vaadin.ui.UI;
-import static com.vaadin.tests.tb3.TB3Runner.localWebDriverIsUsed;
-
/**
* Base class for TestBench 3+ tests. All TB3+ tests in the project should
* extend this class.
@@ -85,6 +90,8 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
*/
private static final int BROWSER_TIMEOUT_IN_MS = 30 * 1000;
+ private static final int BROWSER_INIT_ATTEMPTS = 5;
+
private DesiredCapabilities desiredCapabilities;
private boolean debug = false;
@@ -134,9 +141,7 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
if (localWebDriverIsUsed()) {
setupLocalDriver(capabilities);
} else {
- WebDriver dr = TestBench.createDriver(new RemoteWebDriver(
- new URL(getHubURL()), capabilities));
- setDriver(dr);
+ setupRemoteDriver(capabilities);
}
}
@@ -166,7 +171,8 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
}
protected WebElement getTooltipElement() {
- return getDriver().findElement(com.vaadin.testbench.By.className("v-tooltip-text"));
+ return getDriver().findElement(
+ com.vaadin.testbench.By.className("v-tooltip-text"));
}
protected Coordinates getCoordinates(TestBenchElement element) {
@@ -218,12 +224,53 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
DesiredCapabilities desiredCapabilities);
/**
+ * Creates a {@link WebDriver} instance used for running the test remotely.
+ *
+ * @since
+ * @param capabilities
+ * the type of browser needed
+ * @throws Exception
+ */
+ private void setupRemoteDriver(DesiredCapabilities capabilities)
+ throws Exception {
+ for (int i = 1; i <= BROWSER_INIT_ATTEMPTS; i++) {
+ try {
+ WebDriver dr = TestBench.createDriver(new RemoteWebDriver(
+ new URL(getHubURL()), capabilities));
+ setDriver(dr);
+ } catch (Exception e) {
+ System.err.println("Browser startup for " + capabilities
+ + " failed on attempt " + i + ": " + e.getMessage());
+ if (i == BROWSER_INIT_ATTEMPTS) {
+ throw e;
+ }
+ }
+ }
+
+ }
+
+ /**
* Opens the given test (defined by {@link #getTestUrl()}, optionally with
* debug window and/or push (depending on {@link #isDebug()} and
* {@link #isPush()}.
*/
protected void openTestURL() {
- driver.get(getTestUrl());
+ openTestURL("");
+ }
+
+ /**
+ * Opens the given test (defined by {@link #getTestUrl()}, optionally with
+ * debug window and/or push (depending on {@link #isDebug()} and
+ * {@link #isPush()}.
+ */
+ protected void openTestURL(String extraParameters) {
+ String url = getTestUrl();
+ if (url.contains("?")) {
+ url = url + "&" + extraParameters;
+ } else {
+ url = url + "?" + extraParameters;
+ }
+ driver.get(url);
}
/**
@@ -341,8 +388,7 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
* @return Focused element or null
*/
protected WebElement getFocusedElement() {
- Object focusedElement = ((JavascriptExecutor) getDriver())
- .executeScript("return document.activeElement");
+ Object focusedElement = executeScript("return document.activeElement");
if (null != focusedElement) {
return (WebElement) focusedElement;
} else {
@@ -351,6 +397,19 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
}
/**
+ * Executes the given Javascript
+ *
+ * @param script
+ * the script to execute
+ * @return whatever
+ * {@link org.openqa.selenium.JavascriptExecutor#executeScript(String, Object...)}
+ * returns
+ */
+ protected Object executeScript(String script) {
+ return ((JavascriptExecutor) getDriver()).executeScript(script);
+ }
+
+ /**
* Find a Vaadin element based on its id given using Component.setId
*
* @param id
@@ -396,7 +455,7 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
* @param condition
* the condition to wait for to become true
*/
- protected void waitUntil(ExpectedCondition<Boolean> condition) {
+ protected <T> void waitUntil(ExpectedCondition<T> condition) {
waitUntil(condition, 10);
}
@@ -408,7 +467,7 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
* @param condition
* the condition to wait for to become true
*/
- protected void waitUntil(ExpectedCondition<Boolean> condition,
+ protected <T> void waitUntil(ExpectedCondition<T> condition,
long timeoutInSeconds) {
new WebDriverWait(driver, timeoutInSeconds).until(condition);
}
@@ -421,7 +480,7 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
* @param condition
* the condition to wait for to become false
*/
- protected void waitUntilNot(ExpectedCondition<Boolean> condition) {
+ protected <T> void waitUntilNot(ExpectedCondition<T> condition) {
waitUntilNot(condition, 10);
}
@@ -433,14 +492,42 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
* @param condition
* the condition to wait for to become false
*/
- protected void waitUntilNot(ExpectedCondition<Boolean> condition,
+ protected <T> void waitUntilNot(ExpectedCondition<T> condition,
long timeoutInSeconds) {
waitUntil(ExpectedConditions.not(condition), timeoutInSeconds);
}
- protected void waitForElementToBePresent(By by) {
- waitUntil(ExpectedConditions.not(ExpectedConditions
- .invisibilityOfElementLocated(by)));
+ protected void waitForElementPresent(final By by) {
+ waitUntil(ExpectedConditions.presenceOfElementLocated(by));
+ }
+
+ protected void waitForElementVisible(final By by) {
+ waitUntil(ExpectedConditions.visibilityOfElementLocated(by));
+ }
+
+ /**
+ * Checks if the given element has the given class name.
+ *
+ * Matches only full class names, i.e. has ("foo") does not match
+ * class="foobar"
+ *
+ * @param element
+ * @param className
+ * @return
+ */
+ protected boolean hasCssClass(WebElement element, String className) {
+ String classes = element.getAttribute("class");
+ if (classes == null || classes.isEmpty()) {
+ return (className == null || className.isEmpty());
+ }
+
+ for (String cls : classes.split(" ")) {
+ if (className.equals(cls)) {
+ return true;
+ }
+ }
+
+ return false;
}
/**
@@ -817,6 +904,8 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
public static DesiredCapabilities ie(int version) {
DesiredCapabilities c = DesiredCapabilities.internetExplorer();
c.setVersion("" + version);
+ c.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION,
+ true);
return c;
}
diff --git a/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java b/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java
index 15ca97f701..ff824ad98a 100644
--- a/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java
+++ b/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java
@@ -1,12 +1,12 @@
/*
* Copyright 2000-2013 Vaadind Ltd.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -28,6 +28,7 @@ import java.util.Properties;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
+import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
@@ -41,7 +42,7 @@ import com.vaadin.tests.tb3.MultiBrowserTest.Browser;
* Provides values for parameters which depend on where the test is run.
* Parameters should be configured in work/eclipse-run-selected-test.properties.
* A template is available in uitest/.
- *
+ *
* @author Vaadin Ltd
*/
public abstract class PrivateTB3Configuration extends ScreenshotTB3Test {
@@ -105,7 +106,7 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test {
/**
* Gets the hostname that tests are configured to use.
- *
+ *
* @return the host name configuration value
*/
public static String getConfiguredDeploymentHostname() {
@@ -125,7 +126,7 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test {
/**
* Gets the port that tests are configured to use.
- *
+ *
* @return the port configuration value
*/
public static int getConfiguredDeploymentPort() {
@@ -142,7 +143,7 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test {
/**
* Tries to automatically determine the IP address of the machine the test
* is running on.
- *
+ *
* @return An IP address of one of the network interfaces in the machine.
* @throws RuntimeException
* if there was an error or no IP was found
@@ -179,7 +180,7 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test {
/*
* (non-Javadoc)
- *
+ *
* @see com.vaadin.tests.tb3.AbstractTB3Test#setupLocalDriver()
*/
@Override
@@ -209,7 +210,13 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test {
+ " containing the path of your local ChromeDriver installation.");
}
System.setProperty("webdriver.chrome.driver", chromeDriverPath);
- driver = new ChromeDriver();
+
+ // Tells chrome not to show warning
+ // "You are using an unsupported command-line flag: --ignore-certifcate-errors".
+ // #14319
+ ChromeOptions options = new ChromeOptions();
+ options.addArguments("--test-type ");
+ driver = new ChromeDriver(options);
} else if (BrowserUtil.isSafari(desiredCapabilities)) {
driver = new SafariDriver();
} else if (BrowserUtil.isPhantomJS(desiredCapabilities)) {
diff --git a/uitest/src/com/vaadin/tests/tb3/TB3Runner.java b/uitest/src/com/vaadin/tests/tb3/TB3Runner.java
index 5b5a6dcf39..0d540644bf 100644
--- a/uitest/src/com/vaadin/tests/tb3/TB3Runner.java
+++ b/uitest/src/com/vaadin/tests/tb3/TB3Runner.java
@@ -17,8 +17,10 @@
package com.vaadin.tests.tb3;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
@@ -26,6 +28,8 @@ import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runners.BlockJUnit4ClassRunner;
@@ -34,6 +38,8 @@ import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;
import org.openqa.selenium.remote.DesiredCapabilities;
+import org.openqa.selenium.remote.HttpCommandExecutor;
+import org.openqa.selenium.remote.internal.HttpClientFactory;
import com.vaadin.tests.annotations.TestCategory;
import com.vaadin.tests.tb3.AbstractTB3Test.BrowserUtil;
@@ -50,6 +56,13 @@ import com.vaadin.tests.tb3.MultiBrowserTest.Browser;
public class TB3Runner extends BlockJUnit4ClassRunner {
/**
+ * Socket timeout for HTTP connections to the grid hub. The connection is
+ * closed after 30 minutes of inactivity to avoid builds hanging for up to
+ * three hours per connection if the test client crashes/hangs.
+ */
+ private static final int SOCKET_TIMEOUT = 30 * 60 * 1000;
+
+ /**
* This is the total limit of actual JUnit test instances run in parallel
*/
private static final int MAX_CONCURRENT_TESTS;
@@ -67,12 +80,34 @@ public class TB3Runner extends BlockJUnit4ClassRunner {
MAX_CONCURRENT_TESTS = 50;
}
service = Executors.newFixedThreadPool(MAX_CONCURRENT_TESTS);
+
+ // reduce socket timeout to avoid tests hanging for three hours
+ try {
+ Field field = HttpCommandExecutor.class
+ .getDeclaredField("httpClientFactory");
+ assert (Modifier.isStatic(field.getModifiers()));
+ field.setAccessible(true);
+ field.set(null, new HttpClientFactory() {
+ @Override
+ public HttpParams getHttpParams() {
+ HttpParams params = super.getHttpParams();
+ // fifteen minute timeout
+ HttpConnectionParams.setSoTimeout(params, SOCKET_TIMEOUT);
+ return params;
+ }
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(
+ "Changing socket timeout for TestBench failed", e);
+ }
}
protected static boolean localWebDriverIsUsed() {
String useLocalWebDriver = System.getProperty("useLocalWebDriver");
- return useLocalWebDriver != null && useLocalWebDriver.toLowerCase().equals("true");
+ return useLocalWebDriver != null
+ && useLocalWebDriver.toLowerCase().equals("true");
}
public TB3Runner(Class<?> klass) throws InitializationError {