summaryrefslogtreecommitdiffstats
path: root/uitest/src/com
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2014-07-22 10:24:57 +0300
committerLeif Åstrand <leif@vaadin.com>2014-07-22 12:29:59 +0300
commit6ae7843e46ee906adfc99bde71ded5f296caea74 (patch)
treeba15e019a724fd3c70c83c34c4f7c0bac22a4f42 /uitest/src/com
parent1b218a1f9f4713d23b8563acd6257fb912afcc15 (diff)
downloadvaadin-framework-6ae7843e46ee906adfc99bde71ded5f296caea74.tar.gz
vaadin-framework-6ae7843e46ee906adfc99bde71ded5f296caea74.zip
Simulate @RunLocally using eclipse-run-selected-test.properties (#14272)
Change-Id: I4eb9409629f64c17f39b1560062e763270f1f582
Diffstat (limited to 'uitest/src/com')
-rw-r--r--uitest/src/com/vaadin/tests/components/upload/TestFileUploadTest.java2
-rw-r--r--uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java15
-rw-r--r--uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java39
-rw-r--r--uitest/src/com/vaadin/tests/tb3/TB3Runner.java16
4 files changed, 57 insertions, 15 deletions
diff --git a/uitest/src/com/vaadin/tests/components/upload/TestFileUploadTest.java b/uitest/src/com/vaadin/tests/components/upload/TestFileUploadTest.java
index 1887427a72..ae966a5b07 100644
--- a/uitest/src/com/vaadin/tests/components/upload/TestFileUploadTest.java
+++ b/uitest/src/com/vaadin/tests/components/upload/TestFileUploadTest.java
@@ -109,7 +109,7 @@ public class TestFileUploadTest extends MultiBrowserTest {
}
private void setLocalFileDetector(WebElement element) throws Exception {
- if (getClass().isAnnotationPresent(RunLocally.class)) {
+ if (getRunLocallyBrowser() != null) {
return;
}
diff --git a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
index 74ddc6cb0c..8dd10216d2 100644
--- a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
+++ b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
@@ -120,13 +120,13 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
protected void setupDriver() throws Exception {
DesiredCapabilities capabilities;
- RunLocally runLocally = getClass().getAnnotation(RunLocally.class);
- if (runLocally != null) {
+ Browser runLocallyBrowser = getRunLocallyBrowser();
+ if (runLocallyBrowser != null) {
if (System.getenv().containsKey("TEAMCITY_VERSION")) {
throw new RuntimeException(
"@RunLocally is not supported for tests run on the build server");
}
- capabilities = runLocally.value().getDesiredCapabilities();
+ capabilities = runLocallyBrowser.getDesiredCapabilities();
setupLocalDriver(capabilities);
} else {
capabilities = getDesiredCapabilities();
@@ -156,6 +156,15 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
}
+ protected Browser getRunLocallyBrowser() {
+ RunLocally runLocally = getClass().getAnnotation(RunLocally.class);
+ if (runLocally != null) {
+ return runLocally.value();
+ } else {
+ return null;
+ }
+ }
+
protected WebElement getTooltipElement() {
return getDriver().findElement(com.vaadin.testbench.By.className("v-tooltip-text"));
}
diff --git a/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java b/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java
index faa74d6c9d..15ca97f701 100644
--- a/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java
+++ b/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
+import java.util.Arrays;
import java.util.Enumeration;
import java.util.Properties;
@@ -34,6 +35,7 @@ import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.safari.SafariDriver;
import com.vaadin.testbench.TestBench;
+import com.vaadin.tests.tb3.MultiBrowserTest.Browser;
/**
* Provides values for parameters which depend on where the test is run.
@@ -43,6 +45,7 @@ import com.vaadin.testbench.TestBench;
* @author Vaadin Ltd
*/
public abstract class PrivateTB3Configuration extends ScreenshotTB3Test {
+ private static final String RUN_LOCALLY_PROPERTY = "com.vaadin.testbench.runLocally";
private static final String HOSTNAME_PROPERTY = "com.vaadin.testbench.deployment.hostname";
private static final String PORT_PROPERTY = "com.vaadin.testbench.deployment.port";
private static final Properties properties = new Properties();
@@ -67,6 +70,16 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test {
return property;
}
+ private static String getSource(String propertyName) {
+ if (properties.containsKey(propertyName)) {
+ return propertiesFile.getAbsolutePath();
+ } else if (System.getProperty(propertyName) != null) {
+ return "System.getProperty()";
+ } else {
+ return null;
+ }
+ }
+
@Override
protected String getScreenshotDirectory() {
String screenshotDirectory = getProperty("com.vaadin.testbench.screenshot.directory");
@@ -84,7 +97,7 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test {
@Override
protected String getDeploymentHostname() {
- if (getClass().getAnnotation(RunLocally.class) != null) {
+ if (getRunLocallyBrowser() != null) {
return "localhost";
}
return getConfiguredDeploymentHostname();
@@ -210,4 +223,28 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test {
setDriver(TestBench.createDriver(driver));
setDesiredCapabilities(desiredCapabilities);
}
+
+ @Override
+ protected Browser getRunLocallyBrowser() {
+ Browser runLocallyBrowser = super.getRunLocallyBrowser();
+ if (runLocallyBrowser != null) {
+ // Always use annotation value if present
+ return runLocallyBrowser;
+ }
+
+ String runLocallyValue = getProperty(RUN_LOCALLY_PROPERTY);
+ if (runLocallyValue == null || runLocallyValue.trim().isEmpty()) {
+ return null;
+ }
+
+ String browserName = runLocallyValue.trim().toUpperCase();
+ try {
+ return Browser.valueOf(browserName);
+ } catch (IllegalArgumentException e) {
+ throw new RuntimeException("Invalid " + RUN_LOCALLY_PROPERTY
+ + " property from " + getSource(RUN_LOCALLY_PROPERTY)
+ + ": " + runLocallyValue + ". Expected one of "
+ + Arrays.toString(Browser.values()));
+ }
+ }
}
diff --git a/uitest/src/com/vaadin/tests/tb3/TB3Runner.java b/uitest/src/com/vaadin/tests/tb3/TB3Runner.java
index 4d29e479e2..5b5a6dcf39 100644
--- a/uitest/src/com/vaadin/tests/tb3/TB3Runner.java
+++ b/uitest/src/com/vaadin/tests/tb3/TB3Runner.java
@@ -37,7 +37,7 @@ import org.openqa.selenium.remote.DesiredCapabilities;
import com.vaadin.tests.annotations.TestCategory;
import com.vaadin.tests.tb3.AbstractTB3Test.BrowserUtil;
-import com.vaadin.tests.tb3.AbstractTB3Test.RunLocally;
+import com.vaadin.tests.tb3.MultiBrowserTest.Browser;
/**
* This runner is loosely based on FactoryTestRunner by Ted Young
@@ -185,17 +185,17 @@ public class TB3Runner extends BlockJUnit4ClassRunner {
/*
* Returns a list of desired browser capabilities according to browsers
* defined in the test class, filtered by possible filter parameters. Use
- * {@code @RunLocally} annotation to override all capabilities.
+ * {@code @RunLocally} annotation or com.vaadin.testbench.runLocally
+ * property to override all capabilities.
*/
private Collection<DesiredCapabilities> getDesiredCapabilities(
AbstractTB3Test testClassInstance) {
Collection<DesiredCapabilities> desiredCapabilites = getFilteredCapabilities(testClassInstance);
- if (isRunLocally(testClassInstance)) {
+ Browser runLocallyBrowser = testClassInstance.getRunLocallyBrowser();
+ if (runLocallyBrowser != null) {
desiredCapabilites = new ArrayList<DesiredCapabilities>();
- desiredCapabilites.add(testClassInstance.getClass()
- .getAnnotation(RunLocally.class).value()
- .getDesiredCapabilities());
+ desiredCapabilites.add(runLocallyBrowser.getDesiredCapabilities());
}
return desiredCapabilites;
@@ -237,10 +237,6 @@ public class TB3Runner extends BlockJUnit4ClassRunner {
return filteredCapabilities;
}
- private boolean isRunLocally(AbstractTB3Test testClassInstance) {
- return testClassInstance.getClass().getAnnotation(RunLocally.class) != null;
- }
-
private AbstractTB3Test getTestClassInstance()
throws InstantiationException, IllegalAccessException,
InvocationTargetException {