diff options
author | Artur Signell <artur@vaadin.com> | 2013-09-16 14:44:43 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-09-25 11:22:28 +0000 |
commit | a2daf65958c602dd02099bf4415e7e432b706dc7 (patch) | |
tree | 357c599a8249f887fa8a4da62e780c8c6cc7576a /uitest/src/com/vaadin/tests/tb3 | |
parent | 1df28c314141d7531591ff9c5ee1ab3521f29e8c (diff) | |
download | vaadin-framework-a2daf65958c602dd02099bf4415e7e432b706dc7.tar.gz vaadin-framework-a2daf65958c602dd02099bf4415e7e432b706dc7.zip |
Converted TB2 push tests to TB3 (#12580)
Change-Id: Ifd6286aee75946eb47c39886c08473a5a0c10545
Diffstat (limited to 'uitest/src/com/vaadin/tests/tb3')
-rw-r--r-- | uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java | 91 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java | 31 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/tb3/TB3Runner.java | 51 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/tb3/WebsocketTest.java | 60 |
4 files changed, 162 insertions, 71 deletions
diff --git a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java index 63819e5f07..1897728366 100644 --- a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java @@ -17,18 +17,24 @@ package com.vaadin.tests.tb3; import java.net.URL; +import java.util.Collection; +import java.util.Collections; import org.junit.After; import org.junit.Before; +import org.junit.runner.RunWith; +import org.openqa.selenium.By; import org.openqa.selenium.Platform; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.BrowserType; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; +import org.openqa.selenium.support.ui.ExpectedCondition; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; import com.vaadin.server.LegacyApplication; -import com.vaadin.testbench.By; import com.vaadin.testbench.TestBench; import com.vaadin.testbench.TestBenchTestCase; import com.vaadin.ui.UI; @@ -50,6 +56,7 @@ import com.vaadin.ui.UI; * * @author Vaadin Ltd */ +@RunWith(value = TB3Runner.class) public abstract class AbstractTB3Test extends TestBenchTestCase { /** * Height of the screenshots we want to capture @@ -154,6 +161,24 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { protected abstract String getDeploymentHostname(); /** + * Produces a collection of browsers to run the test on. This method is + * executed by the test runner when determining how many test methods to + * invoke and with what parameters. For each returned value a test method is + * ran and before running that, + * {@link #setDesiredCapabilities(DesiredCapabilities)} is invoked with the + * value returned by this method. + * + * This method is not static to allow overriding it in sub classes. By + * default runs the test only on Firefox + * + * @return The browsers to run the test on + */ + public Collection<DesiredCapabilities> getBrowsersToTest() { + return Collections.singleton(BrowserUtil.firefox(17)); + + } + + /** * Used to determine which capabilities should be used when setting up a * {@link WebDriver} for this test. Typically set by a test runner or left * at its default (Firefox 24). If you want to run a test on a single @@ -189,9 +214,8 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { } /** - * Finds a Vaadin element based on the part of a TB3 style locator following - * the :: (e.g. - * vaadin=runLabelModes::PID_Scheckboxaction-Enabled/domChild[0] -> + * Finds an element based on the part of a TB2 style locator following the + * :: (e.g. vaadin=runLabelModes::PID_Scheckboxaction-Enabled/domChild[0] -> * PID_Scheckboxaction-Enabled/domChild[0]). * * @param vaadinLocator @@ -199,11 +223,7 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { * @return */ protected WebElement vaadinElement(String vaadinLocator) { - String base = getApplicationId(getDeploymentPath()); - - base += "::"; - - return driver.findElement(By.vaadin(base + vaadinLocator)); + return driver.findElement(vaadinLocator(vaadinLocator)); } /** @@ -214,7 +234,58 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { * @return */ public WebElement vaadinElementById(String id) { - return vaadinElement("PID_S" + id); + return driver.findElement(vaadinLocatorById(id)); + } + + /** + * Finds a {@link By} locator based on the part of a TB2 style locator + * following the :: (e.g. + * vaadin=runLabelModes::PID_Scheckboxaction-Enabled/domChild[0] -> + * PID_Scheckboxaction-Enabled/domChild[0]). + * + * @param vaadinLocator + * The part following :: of the vaadin locator string + * @return + */ + public org.openqa.selenium.By vaadinLocator(String vaadinLocator) { + String base = getApplicationId(getDeploymentPath()); + + base += "::"; + return com.vaadin.testbench.By.vaadin(base + vaadinLocator); + } + + /** + * Constructs a {@link By} locator for the id given using Component.setId + * + * @param id + * The id to locate + * @return a locator for the given id + */ + public By vaadinLocatorById(String id) { + return vaadinLocator("PID_S" + id); + } + + /** + * Waits a short while for the given condition to become true. Use e.g. as + * {@link #waitUntil(ExpectedConditions.textToBePresentInElement(by, text))} + * + * @param condition + * the condition to wait for to become true + */ + protected void waitUntil(ExpectedCondition<Boolean> condition) { + new WebDriverWait(driver, 10).until(condition); + } + + /** + * Waits a short while for the given condition to become false. Use e.g. as + * {@link #waitUntilNot(ExpectedConditions.textToBePresentInElement(by, + * text))} + * + * @param condition + * the condition to wait for to become false + */ + protected void waitUntilNot(ExpectedCondition<Boolean> condition) { + new WebDriverWait(driver, 10).until(ExpectedConditions.not(condition)); } /** diff --git a/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java b/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java index e24218eeb4..3553954ec0 100644 --- a/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java +++ b/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java @@ -18,11 +18,8 @@ package com.vaadin.tests.tb3; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized.Parameters; import org.openqa.selenium.remote.DesiredCapabilities; /** @@ -41,11 +38,9 @@ import org.openqa.selenium.remote.DesiredCapabilities; * * @author Vaadin Ltd */ -@RunWith(value = TB3Runner.class) public abstract class MultiBrowserTest extends PrivateTB3Configuration { - private static List<DesiredCapabilities> allBrowsers = new ArrayList<DesiredCapabilities>(); - private static List<DesiredCapabilities> websocketBrowsers = new ArrayList<DesiredCapabilities>(); + static List<DesiredCapabilities> allBrowsers = new ArrayList<DesiredCapabilities>(); static { allBrowsers.add(BrowserUtil.ie(8)); allBrowsers.add(BrowserUtil.ie(9)); @@ -57,26 +52,18 @@ public abstract class MultiBrowserTest extends PrivateTB3Configuration { allBrowsers.add(BrowserUtil.chrome(29)); allBrowsers.add(BrowserUtil.opera(12)); - websocketBrowsers.addAll(allBrowsers); - websocketBrowsers.remove(BrowserUtil.ie(8)); - websocketBrowsers.remove(BrowserUtil.ie(9)); - } - - @Parameters - public static Collection<DesiredCapabilities> getBrowsersForTest() { - return getAllBrowsers(); - } - - public static Collection<DesiredCapabilities> getAllBrowsers() { - return Collections.unmodifiableCollection(allBrowsers); } /** - * @return A subset of {@link #getAllBrowsers()} including only those which - * support websockets + * @return all supported browsers which are actively tested */ - public static Collection<DesiredCapabilities> getWebsocketBrowsers() { - return Collections.unmodifiableCollection(websocketBrowsers); + public static List<DesiredCapabilities> getAllBrowsers() { + return allBrowsers; + } + + @Override + public Collection<DesiredCapabilities> getBrowsersToTest() { + return allBrowsers; } } diff --git a/uitest/src/com/vaadin/tests/tb3/TB3Runner.java b/uitest/src/com/vaadin/tests/tb3/TB3Runner.java index 510d200ffa..5860ac42c0 100644 --- a/uitest/src/com/vaadin/tests/tb3/TB3Runner.java +++ b/uitest/src/com/vaadin/tests/tb3/TB3Runner.java @@ -17,16 +17,12 @@ package com.vaadin.tests.tb3; import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.Arrays; -import java.util.Collections; import java.util.LinkedList; import java.util.List; import org.junit.Test; import org.junit.runners.BlockJUnit4ClassRunner; import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.InitializationError; import org.junit.runners.model.Statement; @@ -53,49 +49,26 @@ public class TB3Runner extends BlockJUnit4ClassRunner { protected List<FrameworkMethod> computeTestMethods() { List<FrameworkMethod> tests = new LinkedList<FrameworkMethod>(); - // Find all methods in our test class marked with @Parameters. - for (FrameworkMethod method : getTestClass().getAnnotatedMethods( - Parameters.class)) { - // Make sure the Parameters method is static - if (!Modifier.isStatic(method.getMethod().getModifiers())) { - throw new IllegalArgumentException("@Parameters " + method - + " must be static."); - } - - // Execute the method (statically) - Object params; - try { - params = method.getMethod().invoke( - getTestClass().getJavaClass()); - } catch (Throwable t) { - throw new RuntimeException("Could not run test factory method " - + method.getName(), t); - } - - // Did the factory return an array? If so, make it a list. - if (params.getClass().isArray()) { - params = Arrays.asList((Object[]) params); - } + if (!AbstractTB3Test.class.isAssignableFrom(getTestClass() + .getJavaClass())) { + throw new RuntimeException(getClass().getName() + " only supports " + + AbstractTB3Test.class.getName()); + } - // Did the factory return a scalar object? If so, put it in a list. - if (!(params instanceof Iterable<?>)) { - params = Collections.singletonList(params); - } + try { + AbstractTB3Test testClassInstance = (AbstractTB3Test) getTestClass() + .getOnlyConstructor().newInstance(); + for (DesiredCapabilities capabilities : testClassInstance + .getBrowsersToTest()) { - // For each object returned by the factory. - for (Object param : (Iterable<?>) params) { - if (!(param instanceof DesiredCapabilities)) { - throw new RuntimeException("Unexpected parameter type " - + param.getClass().getName() - + " when expecting DesiredCapabilities"); - } - DesiredCapabilities capabilities = (DesiredCapabilities) param; // Find any methods marked with @Test. for (FrameworkMethod m : getTestClass().getAnnotatedMethods( Test.class)) { tests.add(new TB3Method(m.getMethod(), capabilities)); } } + } catch (Exception e) { + throw new RuntimeException("Error retrieving browsers to run on", e); } return tests; diff --git a/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java b/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java new file mode 100644 index 0000000000..5c6ea329f5 --- /dev/null +++ b/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java @@ -0,0 +1,60 @@ +/* + * Copyright 2000-2013 Vaadin 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 + * License for the specific language governing permissions and limitations under + * the License. + */ + +/** + * + */ +package com.vaadin.tests.tb3; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.openqa.selenium.remote.DesiredCapabilities; + +/** + * A {@link MultiBrowserTest} which restricts the tests to the browsers which + * support websocket + * + * @author Vaadin Ltd + */ +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)); + } + + /** + * @return All supported browsers which are actively tested and support + * websockets + */ + public static Collection<DesiredCapabilities> getWebsocketBrowsers() { + return Collections.unmodifiableCollection(websocketBrowsers); + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.tb3.AbstractTB3Test#getBrowserToRunOn() + */ + @Override + public Collection<DesiredCapabilities> getBrowsersToTest() { + return getWebsocketBrowsers(); + } +} |