From 12d504328c7a948dc953f522b879d7c831bf36c0 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Wed, 5 Sep 2018 13:35:53 +0300 Subject: [PATCH] Add configuration for BrowserStack testing (#11164) --- uitest/pom.xml | 1 + .../tests/tb3/BrowserStackBrowserFactory.java | 29 ++++++++----------- .../tests/tb3/PrivateTB3Configuration.java | 21 ++++++++++---- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/uitest/pom.xml b/uitest/pom.xml index 6e71095853..5965f7dae9 100644 --- a/uitest/pom.xml +++ b/uitest/pom.xml @@ -331,6 +331,7 @@ ${browsers.exclude} ${categories.exclude} ${browser.factory} + ${browserstack.identifier} diff --git a/uitest/src/test/java/com/vaadin/tests/tb3/BrowserStackBrowserFactory.java b/uitest/src/test/java/com/vaadin/tests/tb3/BrowserStackBrowserFactory.java index b8543ca820..e369f69438 100644 --- a/uitest/src/test/java/com/vaadin/tests/tb3/BrowserStackBrowserFactory.java +++ b/uitest/src/test/java/com/vaadin/tests/tb3/BrowserStackBrowserFactory.java @@ -21,21 +21,18 @@ public class BrowserStackBrowserFactory extends DefaultBrowserFactory { DesiredCapabilities caps; switch (browser) { + /* Ignored browsers */ case CHROME: caps = DesiredCapabilities.chrome(); - caps.setVersion(version); break; case PHANTOMJS: // This will not work on BrowserStack - should be filtered with // browsers.exclude. However, we cannot throw an exception here as // filtering only takes place if there is no exception. caps = DesiredCapabilities.phantomjs(); - caps.setVersion("1"); - caps.setPlatform(Platform.LINUX); break; case SAFARI: caps = DesiredCapabilities.safari(); - caps.setVersion(version); break; case IE8: caps = DesiredCapabilities.internetExplorer(); @@ -75,34 +72,32 @@ public class BrowserStackBrowserFactory extends DefaultBrowserFactory { break; case FIREFOX: caps = DesiredCapabilities.firefox(); - caps.setVersion(version); break; default: caps = DesiredCapabilities.firefox(); - caps.setVersion(version); - caps.setPlatform(platform); } // BrowserStack specific parts // for now, run all tests on Windows 7 - if (!Browser.PHANTOMJS.equals(browser)) { - caps.setCapability("os", "Windows"); - caps.setCapability("os_version", "7"); - caps.setPlatform(Platform.WINDOWS); - } + caps.setCapability("os", "Windows"); + caps.setCapability("os_version", "7"); + caps.setPlatform(Platform.WINDOWS); // enable logging on BrowserStack caps.setCapability("browserstack.debug", "true"); // tunnel caps.setCapability("browserstack.local", "true"); - // optionally, could also set browserstack.localIdentifier if we have a - // tunnel name + String localIdentifier = System.getProperty("browserstack.identifier", ""); + if (!localIdentifier.isEmpty()) { + caps.setCapability("browserstack.localIdentifier", localIdentifier); + } - // build and project for easy identification in BrowserStack UI - caps.setCapability("project", "vaadin"); - caps.setCapability("build", Version.getFullVersion()); + // build name for easy identification in BrowserStack UI + caps.setCapability("build", + "BrowserStack Tests" + (localIdentifier.isEmpty() ? "" + : " [" + localIdentifier + "]")); // accept self-signed certificates caps.setCapability("acceptSslCerts", "true"); diff --git a/uitest/src/test/java/com/vaadin/tests/tb3/PrivateTB3Configuration.java b/uitest/src/test/java/com/vaadin/tests/tb3/PrivateTB3Configuration.java index 36de54db26..827991dbfa 100644 --- a/uitest/src/test/java/com/vaadin/tests/tb3/PrivateTB3Configuration.java +++ b/uitest/src/test/java/com/vaadin/tests/tb3/PrivateTB3Configuration.java @@ -65,12 +65,12 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test { private static final String BROWSERS_EXCLUDE = "browsers.exclude"; private static final String CATEGORIES_INCLUDE = "categories.include"; private static final String CATEGORIES_EXCLUDE = "categories.exclude"; + private static final String BROWSERSTACK_IDENTIFIER = "browserstack.identifier"; static { if (propertiesFile.exists()) { try { properties.load(new FileInputStream(propertiesFile)); - System.err.println("LOADED"); } catch (IOException e) { throw new RuntimeException(e); } @@ -84,7 +84,14 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test { + localBrowser.getVersion()); } - String[] vars = new String[] {FIREFOX_PATH, BROWSER_FACTORY, BROWSERS_INCLUDE, BROWSERS_EXCLUDE, CATEGORIES_INCLUDE, CATEGORIES_EXCLUDE}; + if ("true".equals(getProperty("browserstack"))) { + properties.setProperty(HUB_URL, + "https://" + getProperty("browserstack.username") + ":" + + getProperty("browserstack.key") + + "@hub-cloud.browserstack.com/wd/hub"); + } + + String[] vars = new String[] {FIREFOX_PATH, BROWSER_FACTORY, BROWSERS_INCLUDE, BROWSERS_EXCLUDE, CATEGORIES_INCLUDE, CATEGORIES_EXCLUDE, BROWSERSTACK_IDENTIFIER}; for (String var : vars) { if (properties.containsKey(var)) { @@ -138,9 +145,13 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test { } } - desiredCapabilities.setCapability("project", "Vaadin Framework"); - desiredCapabilities.setCapability("build", String.format("%s / %s", - getDeploymentHostname(), Calendar.getInstance().getTime())); + if (desiredCapabilities.getCapability("project") == null) { + desiredCapabilities.setCapability("project", "Vaadin Framework"); + } + if (desiredCapabilities.getCapability("build") == null) { + desiredCapabilities.setCapability("build", String.format("%s / %s", + getDeploymentHostname(), Calendar.getInstance().getTime())); + } desiredCapabilities.setCapability("name", String.format("%s.%s", getClass().getCanonicalName(), testName.getMethodName())); } -- 2.39.5