]> source.dussan.org Git - vaadin-framework.git/commitdiff
Allow using @RunLocally to run on a local Firefox/Chrome/Safari
authorArtur Signell <artur@vaadin.com>
Thu, 14 Nov 2013 07:38:05 +0000 (09:38 +0200)
committerArtur Signell <artur@vaadin.com>
Fri, 15 Nov 2013 13:41:02 +0000 (15:41 +0200)
Change-Id: Ibb1dfd12dc48637d8179f80322b5203ea5562805

uitest/src/com/vaadin/tests/VerifyBrowserVersionTest.java
uitest/src/com/vaadin/tests/actions/ActionsOnInvisibleComponentsTest.java
uitest/src/com/vaadin/tests/components/nativeselect/NativeSelectsAndChromeKeyboardNavigationTest.java
uitest/src/com/vaadin/tests/integration/AbstractIntegrationTest.java
uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java
uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java
uitest/src/com/vaadin/tests/tb3/TB3Runner.java
uitest/src/com/vaadin/tests/tb3/WebsocketTest.java

index ae5806af56f278d3743b612197535775afe68aca..bb0b40e2d1704f487650d9c572466989c80a7f03 100644 (file)
@@ -30,23 +30,22 @@ public class VerifyBrowserVersionTest extends MultiBrowserTest {
 
     {
         expectedUserAgent
-                .put(BrowserUtil
-                        .firefox(MultiBrowserTest.TESTED_FIREFOX_VERSION),
+                .put(Browser.FIREFOX.getDesiredCapabilities(),
                         "Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0");
         expectedUserAgent
-                .put(BrowserUtil.ie(8),
+                .put(Browser.IE8.getDesiredCapabilities(),
                         "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");
         expectedUserAgent
-                .put(BrowserUtil.ie(9),
+                .put(Browser.IE9.getDesiredCapabilities(),
                         "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)");
         expectedUserAgent
-                .put(BrowserUtil.ie(10),
+                .put(Browser.IE10.getDesiredCapabilities(),
                         "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)");
         expectedUserAgent
-                .put(BrowserUtil.ie(11),
+                .put(Browser.IE11.getDesiredCapabilities(),
                         "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko");
         expectedUserAgent
-                .put(BrowserUtil.chrome(MultiBrowserTest.TESTED_CHROME_VERSION),
+                .put(Browser.CHROME.getDesiredCapabilities(),
                         "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36");
 
     }
index ca00c998a62177f2e372e1d510acd5ad2ca6a6e9..1d08ee5edea2c4ca4c4e10ea07278774798c025d 100644 (file)
@@ -18,12 +18,12 @@ public class ActionsOnInvisibleComponentsTest extends MultiBrowserTest {
     public List<DesiredCapabilities> getBrowsersToTest() {
         List<DesiredCapabilities> browsers = super.getBrowsersToTest();
         // sendKeys does nothing on these browsers
-        browsers.remove(BrowserUtil.firefox(24));
-        browsers.remove(BrowserUtil.ie(8));
-        browsers.remove(BrowserUtil.opera(12));
+        browsers.remove(Browser.FIREFOX.getDesiredCapabilities());
+        browsers.remove(Browser.IE8.getDesiredCapabilities());
+        browsers.remove(Browser.OPERA.getDesiredCapabilities());
 
         // Causes 'cannot focus element'
-        browsers.remove(BrowserUtil.chrome(29));
+        browsers.remove(Browser.CHROME.getDesiredCapabilities());
         return browsers;
     }
 
index 364d3bd8d49b3908f877e25e5b1ee379d303ba0d..e038c451d034e09b1ad71185366439720c805137 100644 (file)
@@ -22,7 +22,6 @@ import org.junit.Assert;
 import org.junit.Test;
 import org.openqa.selenium.By;
 import org.openqa.selenium.Keys;
-import org.openqa.selenium.Platform;
 import org.openqa.selenium.WebElement;
 import org.openqa.selenium.interactions.Actions;
 import org.openqa.selenium.remote.DesiredCapabilities;
@@ -44,9 +43,8 @@ public class NativeSelectsAndChromeKeyboardNavigationTest extends
      */
     @Override
     public List<DesiredCapabilities> getBrowsersToTest() {
-        DesiredCapabilities chrome = DesiredCapabilities.chrome();
-        chrome.setPlatform(Platform.WINDOWS);
-        return Collections.singletonList(chrome);
+        return Collections.singletonList(Browser.CHROME
+                .getDesiredCapabilities());
     }
 
     @Test
@@ -84,30 +82,6 @@ public class NativeSelectsAndChromeKeyboardNavigationTest extends
         return NativeSelects.class;
     }
 
-    // Uncomment this to debug test in local/portforwarded chromedriver
-    // @Override
-    // protected void setupLocalDriver() {
-    // WebDriver chromeDriver;
-    // try {
-    // chromeDriver = new RemoteWebDriver(
-    // new URL("http://localhost:9515"), getBrowsersToTest()
-    // .iterator().next());
-    // setDriver(chromeDriver);
-    // } catch (MalformedURLException e) {
-    // e.printStackTrace();
-    // }
-    // }
-    //
-    // /*
-    // * (non-Javadoc)
-    // *
-    // * @see com.vaadin.tests.tb3.AbstractTB3Test#runLocally()
-    // */
-    // @Override
-    // public boolean runLocally() {
-    // return false;
-    // }
-
     /**
      * @since
      * @param string
index ddaf84b3e1d69b1dc68801094355d3a65e1bc9b6..cbb3a8b8e423664ae6420d5913ca43ab12e6c7e3 100644 (file)
@@ -22,7 +22,7 @@ import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized.Parameters;
 import org.openqa.selenium.remote.DesiredCapabilities;
 
-import com.vaadin.tests.tb3.MultiBrowserTest;
+import com.vaadin.tests.tb3.MultiBrowserTest.Browser;
 import com.vaadin.tests.tb3.PrivateTB3Configuration;
 
 /**
@@ -47,8 +47,7 @@ public abstract class AbstractIntegrationTest extends PrivateTB3Configuration {
 
     @Parameters
     public static Collection<DesiredCapabilities> getBrowsersForTest() {
-        return Collections.singleton(BrowserUtil
-                .firefox(MultiBrowserTest.TESTED_FIREFOX_VERSION));
+        return Collections.singleton(Browser.FIREFOX.getDesiredCapabilities());
     }
 
 }
index d4eed99f199b4f3f15f396e618a74a9630907d91..f6e58a51b23c10b3c1a9590f40abdee27452bca7 100644 (file)
 
 package com.vaadin.tests.tb3;
 
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
 import java.net.URL;
 import java.util.Collections;
 import java.util.List;
@@ -39,6 +43,7 @@ import com.vaadin.server.UIProvider;
 import com.vaadin.testbench.TestBench;
 import com.vaadin.testbench.TestBenchTestCase;
 import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.tests.tb3.MultiBrowserTest.Browser;
 import com.vaadin.ui.UI;
 
 /**
@@ -76,8 +81,7 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
     private boolean push = false;
     {
         // Default browser to run on unless setDesiredCapabilities is called
-        desiredCapabilities = BrowserUtil
-                .firefox(MultiBrowserTest.TESTED_FIREFOX_VERSION);
+        desiredCapabilities = Browser.FIREFOX.getDesiredCapabilities();
     }
 
     /**
@@ -103,8 +107,9 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
      *             If something goes wrong
      */
     protected void setupDriver() throws Exception {
-        if (runLocally()) {
-            setupLocalDriver();
+        RunLocally runLocally = getClass().getAnnotation(RunLocally.class);
+        if (runLocally != null) {
+            setupLocalDriver(runLocally.value().getDesiredCapabilities());
             return;
         }
         DesiredCapabilities capabilities = getDesiredCapabilities();
@@ -129,14 +134,10 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
 
     }
 
-    /**
-     * Override and return true to run the test locally. This method is only to
-     * be used for developing tests.
-     * 
-     * @return true to run the test on a local browser, false to use the hub
-     */
-    public boolean runLocally() {
-        return false;
+    @Retention(RetentionPolicy.RUNTIME)
+    @Target(ElementType.TYPE)
+    public @interface RunLocally {
+        public Browser value() default Browser.FIREFOX;
     }
 
     /**
@@ -144,7 +145,8 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
      * for debug purposes. Used only when {@link #runLocally()} is overridden to
      * return true;
      */
-    protected abstract void setupLocalDriver();
+    protected abstract void setupLocalDriver(
+            DesiredCapabilities desiredCapabilities);
 
     /**
      * Opens the given test (defined by {@link #getTestUrl()}, optionally with
@@ -212,9 +214,8 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
      * @return The browsers to run the test on
      */
     public List<DesiredCapabilities> getBrowsersToTest() {
-        return Collections.singletonList(BrowserUtil
-                .firefox(MultiBrowserTest.TESTED_FIREFOX_VERSION));
-
+        return Collections.singletonList(Browser.FIREFOX
+                .getDesiredCapabilities());
     }
 
     /**
@@ -738,8 +739,53 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
          * @return true if the capabilities refer to IE8, false otherwise
          */
         public static boolean isIE8(DesiredCapabilities capabilities) {
-            return BrowserType.IE.equals(capabilities.getBrowserName())
-                    && "8".equals(capabilities.getVersion());
+            return isIE(capabilities) && "8".equals(capabilities.getVersion());
+        }
+
+        /**
+         * @param capabilities
+         *            The capabilities to check
+         * @return true if the capabilities refer to Internet Explorer, false
+         *         otherwise
+         */
+        public static boolean isIE(DesiredCapabilities capabilities) {
+            return BrowserType.IE.equals(capabilities.getBrowserName());
+        }
+
+        /**
+         * @param capabilities
+         *            The capabilities to check
+         * @return true if the capabilities refer to Chrome, false otherwise
+         */
+        public static boolean isChrome(DesiredCapabilities capabilities) {
+            return BrowserType.CHROME.equals(capabilities.getBrowserName());
+        }
+
+        /**
+         * @param capabilities
+         *            The capabilities to check
+         * @return true if the capabilities refer to Opera, false otherwise
+         */
+        public static boolean isOpera(DesiredCapabilities capabilities) {
+            return BrowserType.OPERA.equals(capabilities.getBrowserName());
+        }
+
+        /**
+         * @param capabilities
+         *            The capabilities to check
+         * @return true if the capabilities refer to Safari, false otherwise
+         */
+        public static boolean isSafari(DesiredCapabilities capabilities) {
+            return BrowserType.SAFARI.equals(capabilities.getBrowserName());
+        }
+
+        /**
+         * @param capabilities
+         *            The capabilities to check
+         * @return true if the capabilities refer to Firefox, false otherwise
+         */
+        public static boolean isFirefox(DesiredCapabilities capabilities) {
+            return BrowserType.FIREFOX.equals(capabilities.getBrowserName());
         }
 
         /**
@@ -751,21 +797,19 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
          */
         public static String getBrowserIdentifier(
                 DesiredCapabilities capabilities) {
-            String browserName = capabilities.getBrowserName();
-
-            if (BrowserType.IE.equals(browserName)) {
+            if (isIE(capabilities)) {
                 return "InternetExplorer";
-            } else if (BrowserType.FIREFOX.equals(browserName)) {
+            } else if (isFirefox(capabilities)) {
                 return "Firefox";
-            } else if (BrowserType.CHROME.equals(browserName)) {
+            } else if (isChrome(capabilities)) {
                 return "Chrome";
-            } else if (BrowserType.SAFARI.equals(browserName)) {
+            } else if (isSafari(capabilities)) {
                 return "Safari";
-            } else if (BrowserType.OPERA.equals(browserName)) {
+            } else if (isOpera(capabilities)) {
                 return "Opera";
             }
 
-            return browserName;
+            return capabilities.getBrowserName();
         }
 
         /**
index e8a974343bced47c80a02c90bcb0684fc7ece8ea..e166e421efeffb0357e88149d5ec02fb2ed1bad8 100644 (file)
@@ -40,23 +40,34 @@ import org.openqa.selenium.remote.DesiredCapabilities;
  */
 public abstract class MultiBrowserTest extends PrivateTB3Configuration {
 
-    public static final int TESTED_SAFARI_VERSION = 7;
-    public static final int TESTED_CHROME_VERSION = 29;
-    public static final int TESTED_FIREFOX_VERSION = 24;
+    public enum Browser {
+        FIREFOX(BrowserUtil.firefox(24)), CHROME(BrowserUtil.chrome(29)), SAFARI(
+                BrowserUtil.safari(7)), IE8(BrowserUtil.ie(8)), IE9(BrowserUtil
+                .ie(9)), IE10(BrowserUtil.ie(10)), IE11(BrowserUtil.ie(11)), OPERA(
+                BrowserUtil.opera(17));
+        private DesiredCapabilities desiredCapabilities;
+
+        private Browser(DesiredCapabilities desiredCapabilities) {
+            this.desiredCapabilities = desiredCapabilities;
+        }
+
+        public DesiredCapabilities getDesiredCapabilities() {
+            return desiredCapabilities;
+        }
+    }
 
     static List<DesiredCapabilities> allBrowsers = new ArrayList<DesiredCapabilities>();
     static {
-        allBrowsers.add(BrowserUtil.ie(8));
-        allBrowsers.add(BrowserUtil.ie(9));
-        allBrowsers.add(BrowserUtil.ie(10));
-        allBrowsers.add(BrowserUtil.ie(11));
-        allBrowsers.add(BrowserUtil.firefox(TESTED_FIREFOX_VERSION));
+        allBrowsers.add(Browser.IE8.getDesiredCapabilities());
+        allBrowsers.add(Browser.IE9.getDesiredCapabilities());
+        allBrowsers.add(Browser.IE10.getDesiredCapabilities());
+        allBrowsers.add(Browser.IE11.getDesiredCapabilities());
+        allBrowsers.add(Browser.FIREFOX.getDesiredCapabilities());
         // Uncomment once we have the capability to run on Safari 6
-        // allBrowsers.add(BrowserUtil.safari(TESTED_SAFARI_VERSION));
-        allBrowsers.add(BrowserUtil.chrome(TESTED_CHROME_VERSION));
+        // allBrowsers.add(SAFARI);
+        allBrowsers.add(Browser.CHROME.getDesiredCapabilities());
         // Re-enable this when it is possible to run on a modern Opera version
-        // (15+)
-        // allBrowsers.add(BrowserUtil.opera(15));
+        // allBrowsers.add(Browser.OPERA.getDesiredCapabilities());
     }
 
     /**
index 89fa304bfe91b017d297d68c6c98f82a659dff55..543484fc1418761d715f1e2a2a626f357f36a30f 100644 (file)
@@ -26,8 +26,11 @@ import java.util.Enumeration;
 import java.util.Properties;
 
 import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.chrome.ChromeDriver;
 import org.openqa.selenium.firefox.FirefoxBinary;
 import org.openqa.selenium.firefox.FirefoxDriver;
+import org.openqa.selenium.remote.DesiredCapabilities;
+import org.openqa.selenium.safari.SafariDriver;
 
 import com.vaadin.testbench.TestBench;
 
@@ -80,7 +83,7 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test {
 
     @Override
     protected String getDeploymentHostname() {
-        if (runLocally()) {
+        if (getClass().getAnnotation(RunLocally.class) != null) {
             return "localhost";
         }
         String hostName = getProperty(HOSTNAME_PROPERTY);
@@ -148,17 +151,29 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test {
      * @see com.vaadin.tests.tb3.AbstractTB3Test#setupLocalDriver()
      */
     @Override
-    protected void setupLocalDriver() {
-        String firefoxPath = getProperty("firefox.path");
+    protected void setupLocalDriver(DesiredCapabilities desiredCapabilities) {
         WebDriver driver;
-        if (firefoxPath != null) {
-            driver = new FirefoxDriver(
-                    new FirefoxBinary(new File(firefoxPath)), null);
+        if (BrowserUtil.isFirefox(desiredCapabilities)) {
+            String firefoxPath = getProperty("firefox.path");
+            if (firefoxPath != null) {
+                driver = new FirefoxDriver(new FirefoxBinary(new File(
+                        firefoxPath)), null);
+            } else {
+                driver = new FirefoxDriver();
+            }
+        } else if (BrowserUtil.isChrome(desiredCapabilities)) {
+            System.setProperty("webdriver.chrome.driver",
+                    getProperty("chrome.driver.path"));
+            driver = new ChromeDriver();
+        } else if (BrowserUtil.isSafari(desiredCapabilities)) {
+            driver = new SafariDriver();
         } else {
-            driver = new FirefoxDriver();
+            throw new RuntimeException(
+                    "Not implemented support for running locally on "
+                            + BrowserUtil
+                                    .getBrowserIdentifier(desiredCapabilities));
         }
         setDriver(TestBench.createDriver(driver));
-        setDesiredCapabilities(BrowserUtil
-                .firefox(MultiBrowserTest.TESTED_FIREFOX_VERSION));
+        setDesiredCapabilities(desiredCapabilities);
     }
 }
index 4e084ab0ed09c397c70bc82f3b97d2e99b3a0171..eaffa80d098c402d35bf96b4f7c79290c8e48b01 100644 (file)
@@ -33,6 +33,7 @@ import org.junit.runners.model.Statement;
 import org.openqa.selenium.remote.DesiredCapabilities;
 
 import com.vaadin.tests.tb3.AbstractTB3Test.BrowserUtil;
+import com.vaadin.tests.tb3.AbstractTB3Test.RunLocally;
 
 /**
  * This runner is loosely based on FactoryTestRunner by Ted Young
@@ -76,10 +77,11 @@ public class TB3Runner extends BlockJUnit4ClassRunner {
                     .getOnlyConstructor().newInstance();
             Collection<DesiredCapabilities> desiredCapabilites = testClassInstance
                     .getBrowsersToTest();
-            if (testClassInstance.runLocally()) {
+            if (testClassInstance.getClass().getAnnotation(RunLocally.class) != null) {
                 desiredCapabilites = new ArrayList<DesiredCapabilities>();
-                desiredCapabilites.add(BrowserUtil
-                        .firefox(MultiBrowserTest.TESTED_FIREFOX_VERSION));
+                desiredCapabilites.add(testClassInstance.getClass()
+                        .getAnnotation(RunLocally.class).value()
+                        .getDesiredCapabilities());
             }
             for (DesiredCapabilities capabilities : desiredCapabilites) {
 
index 26fef667cd671fae8ec89f3d966004f8052df9a3..e9ef11957c0558bde777518e0c900ce240744052 100644 (file)
@@ -25,6 +25,8 @@ import java.util.List;
 
 import org.openqa.selenium.remote.DesiredCapabilities;
 
+import com.vaadin.tests.tb3.MultiBrowserTest.Browser;
+
 /**
  * A {@link MultiBrowserTest} which restricts the tests to the browsers which
  * support websocket
@@ -35,8 +37,8 @@ public abstract class WebsocketTest extends PrivateTB3Configuration {
     private static List<DesiredCapabilities> websocketBrowsers = new ArrayList<DesiredCapabilities>();
     static {
         websocketBrowsers.addAll(MultiBrowserTest.getAllBrowsers());
-        websocketBrowsers.remove(BrowserUtil.ie(8));
-        websocketBrowsers.remove(BrowserUtil.ie(9));
+        websocketBrowsers.remove(Browser.IE8.getDesiredCapabilities());
+        websocketBrowsers.remove(Browser.IE9.getDesiredCapabilities());
     }
 
     /**