diff options
5 files changed, 72 insertions, 15 deletions
diff --git a/uitest/eclipse-run-selected-test.properties b/uitest/eclipse-run-selected-test.properties index cbd1ab1cef..70010fd1da 100644 --- a/uitest/eclipse-run-selected-test.properties +++ b/uitest/eclipse-run-selected-test.properties @@ -1,4 +1,11 @@ ; +; This is an example property file showing how to control how TestBench is used +; in the Vaadin Framework project. You should not modify this file since it's +; under version control. Instead, create a copy of it inside the /work/ folder +; in the project and make your customizations to that file. +; + +; ; For both TestBench 2 and 3 ; @@ -8,6 +15,14 @@ com.vaadin.testbench.screenshot.directory=<enter the full path to the screenshot ; +; For only TestBench 3 +; + +; Simulates @RunLocally with the given value on all test classes without a @RunLocally annotation. +; com.vaadin.testbench.runLocally=firefox + + +; ; For only TestBench 2 ; 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 { |