diff options
Diffstat (limited to 'uitest/src/com/vaadin')
14 files changed, 363 insertions, 286 deletions
diff --git a/uitest/src/com/vaadin/tests/VerifyBrowserVersionTest.java b/uitest/src/com/vaadin/tests/VerifyBrowserVersionTest.java index ae5806af56..bb0b40e2d1 100644 --- a/uitest/src/com/vaadin/tests/VerifyBrowserVersionTest.java +++ b/uitest/src/com/vaadin/tests/VerifyBrowserVersionTest.java @@ -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"); } diff --git a/uitest/src/com/vaadin/tests/actions/ActionsOnInvisibleComponentsTest.java b/uitest/src/com/vaadin/tests/actions/ActionsOnInvisibleComponentsTest.java index ca00c998a6..1d08ee5ede 100644 --- a/uitest/src/com/vaadin/tests/actions/ActionsOnInvisibleComponentsTest.java +++ b/uitest/src/com/vaadin/tests/actions/ActionsOnInvisibleComponentsTest.java @@ -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; } diff --git a/uitest/src/com/vaadin/tests/components/datefield/DateFieldTestTest.java b/uitest/src/com/vaadin/tests/components/datefield/DateFieldTestTest.java index 557201e803..123fd167d0 100644 --- a/uitest/src/com/vaadin/tests/components/datefield/DateFieldTestTest.java +++ b/uitest/src/com/vaadin/tests/components/datefield/DateFieldTestTest.java @@ -35,9 +35,14 @@ public class DateFieldTestTest extends MultiBrowserTest { menu("Component"); menuSub("State"); menu("Required"); + assertRequiredIndicatorVisible(); assertNoErrorNotification(); } + private void assertRequiredIndicatorVisible() { + getDriver().findElement(By.className("v-required-field-indicator")); + } + private void assertNoErrorNotification() { try { getDriver().findElement( @@ -58,6 +63,8 @@ public class DateFieldTestTest extends MultiBrowserTest { menuSub("State"); menu("Required"); + assertRequiredIndicatorVisible(); + menu("Component"); menuSub("Features"); menuSub("Resolution"); @@ -100,8 +107,8 @@ public class DateFieldTestTest extends MultiBrowserTest { * @param string */ private void menuSub(String string) { - getDriver().findElement( - By.xpath("//span[text() = '" + string + "']")).click(); + getDriver().findElement(By.xpath("//span[text() = '" + string + "']")) + .click(); new Actions(getDriver()).moveByOffset(100, 0).build().perform(); } @@ -110,8 +117,8 @@ public class DateFieldTestTest extends MultiBrowserTest { * @param string */ private void menu(String string) { - getDriver().findElement( - By.xpath("//span[text() = '" + string + "']")).click(); + getDriver().findElement(By.xpath("//span[text() = '" + string + "']")) + .click(); } diff --git a/uitest/src/com/vaadin/tests/components/nativeselect/NativeSelectsAndChromeKeyboardNavigationTest.java b/uitest/src/com/vaadin/tests/components/nativeselect/NativeSelectsAndChromeKeyboardNavigationTest.java new file mode 100644 index 0000000000..e038c451d0 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/nativeselect/NativeSelectsAndChromeKeyboardNavigationTest.java @@ -0,0 +1,105 @@ +/* + * 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.components.nativeselect; + +import java.util.Collections; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * + * @since + * @author Vaadin Ltd + */ +public class NativeSelectsAndChromeKeyboardNavigationTest extends + MultiBrowserTest { + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.tb3.MultiBrowserTest#getBrowsersToTest() + */ + @Override + public List<DesiredCapabilities> getBrowsersToTest() { + return Collections.singletonList(Browser.CHROME + .getDesiredCapabilities()); + } + + @Test + public void testValueChangeListenerWithKeyboardNavigation() + throws InterruptedException { + setDebug(true); + openTestURL(); + Thread.sleep(1000); + menu("Component"); + menuSub("Listeners"); + menuSub("Value change listener"); + + getDriver().findElement(By.tagName("body")).click(); + + WebElement select = getDriver().findElement(By.tagName("select")); + select.sendKeys(Keys.ARROW_DOWN); + select.sendKeys(Keys.ARROW_DOWN); + select.sendKeys(Keys.ARROW_DOWN); + + String bodytext = getDriver().findElement(By.tagName("body")).getText(); + + Assert.assertTrue(bodytext.contains("new value: 'Item 1'")); + Assert.assertTrue(bodytext.contains("new value: 'Item 2'")); + Assert.assertTrue(bodytext.contains("new value: 'Item 3'")); + + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.tb3.AbstractTB3Test#getUIClass() + */ + @Override + protected Class<?> getUIClass() { + return NativeSelects.class; + } + + /** + * @since + * @param string + */ + private void menuSub(String string) { + getDriver().findElement(By.xpath("//span[text() = '" + string + "']")) + .click(); + new Actions(getDriver()).moveByOffset(100, 0).build().perform(); + } + + /** + * @since + * @param string + */ + private void menu(String string) { + getDriver().findElement(By.xpath("//span[text() = '" + string + "']")) + .click(); + + } + +} diff --git a/uitest/src/com/vaadin/tests/components/slider/SliderDisableTest.java b/uitest/src/com/vaadin/tests/components/slider/SliderDisableTest.java index f6ec3dac3b..53521ee483 100644 --- a/uitest/src/com/vaadin/tests/components/slider/SliderDisableTest.java +++ b/uitest/src/com/vaadin/tests/components/slider/SliderDisableTest.java @@ -29,6 +29,7 @@ public class SliderDisableTest extends MultiBrowserTest { openTestURL(); WebElement element = vaadinElement("/VVerticalLayout[0]/Slot[0]/VSlider[0]/domChild[2]/domChild[0]"); new Actions(driver).dragAndDropBy(element, 112, 0).perform(); + testBench().waitForVaadin(); compareScreen("enabled"); vaadinElementById("disableButton").click(); compareScreen("disabled"); diff --git a/uitest/src/com/vaadin/tests/components/table/TableHorizontalScrollPositionOnItemSetChange.html b/uitest/src/com/vaadin/tests/components/table/TableHorizontalScrollPositionOnItemSetChange.html deleted file mode 100644 index 6fd54ba0ca..0000000000 --- a/uitest/src/com/vaadin/tests/components/table/TableHorizontalScrollPositionOnItemSetChange.html +++ /dev/null @@ -1,110 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head profile="http://selenium-ide.openqa.org/profiles/test-case"> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> -<link rel="selenium.base" href="http://localhost:8888/" /> -<title>TableHorizontalScrollPositionOnItemSetChange</title> -</head> -<body> - <table cellpadding="1" cellspacing="1" border="1"> - <thead> - <tr> - <td rowspan="1" colspan="3">TableHorizontalScrollPositionOnItemSetChange</td> - </tr> - </thead> - <tbody> - <tr> - <td>open</td> - <td>/run/com.vaadin.tests.components.table.TableHorizontalScrollPositionOnItemSetChange?restartApplication</td> - <td></td> - </tr> - <tr> - <td>scrollLeft</td> - <td>vaadin=runcomvaadintestscomponentstableTableHorizontalScrollPositionOnItemSetChange::PID_Shorscrolltable/domChild[1]</td> - <td>326</td> - </tr> - <tr> - <td>pause</td> - <td>500</td> - <td></td> - </tr> - <tr> - <td>click</td> - <td>vaadin=runcomvaadintestscomponentstableTableHorizontalScrollPositionOnItemSetChange::PID_Slessitems/domChild[0]/domChild[0]</td> - <td></td> - </tr> - <tr> - <td>pause</td> - <td>500</td> - <td></td> - </tr> - <tr> - <td>screenCapture</td> - <td></td> - <td>left-scroll-position-stays-in-middle-with-fewer-items</td> - </tr> - <tr> - <td>click</td> - <td>vaadin=runcomvaadintestscomponentstableTableHorizontalScrollPositionOnItemSetChange::PID_Smoreitems/domChild[0]/domChild[0]</td> - <td></td> - </tr> - <tr> - <td>pause</td> - <td>500</td> - <td></td> - </tr> - <tr> - <td>screenCapture</td> - <td></td> - <td>left-scroll-position-stays-in-middle-with-more-items</td> - </tr> - <tr> - <td>scrollLeft</td> - <td>vaadin=runcomvaadintestscomponentstableTableHorizontalScrollPositionOnItemSetChange::PID_Shorscrolltable/domChild[1]</td> - <td>653</td> - </tr> - <tr> - <td>pause</td> - <td>500</td> - <td></td> - </tr> - <tr> - <td>click</td> - <td>vaadin=runcomvaadintestscomponentstableTableHorizontalScrollPositionOnItemSetChange::PID_Slessitems/domChild[0]/domChild[0]</td> - <td></td> - </tr> - <tr> - <td>pause</td> - <td>500</td> - <td></td> - </tr> - <tr> - <td>screenCapture</td> - <td></td> - <td>left-scroll-position-stays-max-with-fewer-items</td> - </tr> - <tr> - <td>click</td> - <td>vaadin=runcomvaadintestscomponentstableTableHorizontalScrollPositionOnItemSetChange::PID_Smoreitems/domChild[0]/domChild[0]</td> - <td></td> - </tr> - <tr> - <td>pause</td> - <td>500</td> - <td></td> - </tr> - <tr> - <td>screenCapture</td> - <td></td> - <td>left-scroll-position-stays-max-with-more-items</td> - </tr> - <tr> - <td>scrollLeft</td> - <td>vaadin=runcomvaadintestscomponentstableTableHorizontalScrollPositionOnItemSetChange::PID_Shorscrolltable/domChild[1]</td> - <td>0</td> - </tr> - </tbody> - </table> -</body> -</html> diff --git a/uitest/src/com/vaadin/tests/components/table/TableHorizontalScrollPositionOnItemSetChange.java b/uitest/src/com/vaadin/tests/components/table/TableHorizontalScrollPositionOnItemSetChange.java deleted file mode 100644 index 1f59a84428..0000000000 --- a/uitest/src/com/vaadin/tests/components/table/TableHorizontalScrollPositionOnItemSetChange.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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.components.table; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Table; -import com.vaadin.ui.VerticalLayout; - -public class TableHorizontalScrollPositionOnItemSetChange extends - AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - VerticalLayout layout = new VerticalLayout(); - layout.setMargin(true); - layout.setSpacing(true); - setContent(layout); - - final Table table = new Table(); - table.setWidth("640px"); - table.setHeight("243px"); - table.setId("horscrolltable"); - layout.addComponent(table); - - for (int i = 0; i < 15; i++) { - table.addContainerProperty("Column " + i, String.class, null); - } - - for (int i = 0; i < 60; i++) { - table.addItem(); - } - - Button lessItems = new Button("Less items", new Button.ClickListener() { - - @Override - public void buttonClick(Button.ClickEvent event) { - table.removeAllItems(); - for (int i = 0; i < 5; i++) { - table.addItem(); - } - } - }); - lessItems.setId("lessitems"); - - Button moreItems = new Button("More items", new Button.ClickListener() { - - @Override - public void buttonClick(Button.ClickEvent event) { - table.removeAllItems(); - for (int i = 0; i < 50; i++) { - table.addItem(); - } - } - }); - moreItems.setId("moreitems"); - - Button clearItems = new Button("Clear all", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - table.removeAllItems(); - } - }); - - HorizontalLayout buttonLayout = new HorizontalLayout(); - buttonLayout.setSpacing(true); - layout.addComponent(buttonLayout); - - buttonLayout.addComponent(lessItems); - buttonLayout.addComponent(moreItems); - buttonLayout.addComponent(clearItems); - clearItems.setId("clearitems"); - } - - @Override - protected String getTestDescription() { - return "Horizontal scrolling position should not be lost if amount of items changes in Table."; - } - - @Override - protected Integer getTicketNumber() { - return 12652; - } - -} diff --git a/uitest/src/com/vaadin/tests/components/window/SubWindowsTextSelectionTest.java b/uitest/src/com/vaadin/tests/components/window/SubWindowsTextSelectionTest.java new file mode 100644 index 0000000000..1df036af58 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/window/SubWindowsTextSelectionTest.java @@ -0,0 +1,97 @@ +/* + * 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.components.window; + +import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.Point; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Test for issue #12726, IE's make text selection when sub windows are + * dragged(moved). + * + * @since + * @author Vaadin Ltd + */ +public class SubWindowsTextSelectionTest extends MultiBrowserTest { + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.tb3.AbstractTB3Test#getUIClass() + */ + @Override + protected Class<?> getUIClass() { + return SubWindows.class; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.tb3.MultiBrowserTest#getBrowsersToTest() + */ + @Override + public List<DesiredCapabilities> getBrowsersToTest() { + ArrayList<DesiredCapabilities> list = new ArrayList<DesiredCapabilities>(); + list.add(BrowserUtil.ie(9)); + list.add(BrowserUtil.ie(10)); + list.add(BrowserUtil.ie(11)); + return list; + } + + @Test + public void verifyNoTextSelectionOnMove() throws MalformedURLException { + + openTestURL(); + + WebElement element = driver.findElement(By + .className("v-window-outerheader")); + + Point location = element.getLocation(); + + element.click(); + + new Actions(driver).moveToElement(element).perform(); + sleep(100); + // move pointer bit right from the caption text + new Actions(driver).moveByOffset(50, 0).clickAndHold() + .moveByOffset(10, 2).moveByOffset(10, 0).moveByOffset(10, 0) + .moveByOffset(10, 0).release().perform(); + + String selection = ((JavascriptExecutor) getDriver()).executeScript( + "return document.getSelection().toString();").toString(); + + Assert.assertTrue("Text selection was not empty:" + selection, + selection.isEmpty()); + + // Verify also that window was really moved + Point location2 = element.getLocation(); + Assert.assertEquals(location.getX() + (4 * 10), location2.getX()); + + } + +} diff --git a/uitest/src/com/vaadin/tests/integration/AbstractIntegrationTest.java b/uitest/src/com/vaadin/tests/integration/AbstractIntegrationTest.java index ddaf84b3e1..cbb3a8b8e4 100644 --- a/uitest/src/com/vaadin/tests/integration/AbstractIntegrationTest.java +++ b/uitest/src/com/vaadin/tests/integration/AbstractIntegrationTest.java @@ -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()); } } diff --git a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java index d4eed99f19..d7b7cd050f 100644 --- a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java @@ -16,6 +16,10 @@ 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,15 +107,19 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { * If something goes wrong */ protected void setupDriver() throws Exception { - if (runLocally()) { - setupLocalDriver(); - return; - } - DesiredCapabilities capabilities = getDesiredCapabilities(); + DesiredCapabilities capabilities; - WebDriver dr = TestBench.createDriver(new RemoteWebDriver(new URL( - getHubURL()), capabilities)); - setDriver(dr); + RunLocally runLocally = getClass().getAnnotation(RunLocally.class); + if (runLocally != null) { + capabilities = runLocally.value().getDesiredCapabilities(); + setupLocalDriver(capabilities); + } else { + capabilities = getDesiredCapabilities(); + + WebDriver dr = TestBench.createDriver(new RemoteWebDriver(new URL( + getHubURL()), capabilities)); + setDriver(dr); + } int w = SCREENSHOT_WIDTH; int h = SCREENSHOT_HEIGHT; @@ -129,14 +137,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 +148,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 +217,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 +742,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 +800,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(); } /** diff --git a/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java b/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java index e8a974343b..e166e421ef 100644 --- a/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java +++ b/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java @@ -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()); } /** diff --git a/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java b/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java index caa35732d6..543484fc14 100644 --- a/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java +++ b/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java @@ -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,6 +83,9 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test { @Override protected String getDeploymentHostname() { + if (getClass().getAnnotation(RunLocally.class) != null) { + return "localhost"; + } String hostName = getProperty(HOSTNAME_PROPERTY); if (hostName == null || "".equals(hostName)) { @@ -145,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); } } diff --git a/uitest/src/com/vaadin/tests/tb3/TB3Runner.java b/uitest/src/com/vaadin/tests/tb3/TB3Runner.java index 4e084ab0ed..eaffa80d09 100644 --- a/uitest/src/com/vaadin/tests/tb3/TB3Runner.java +++ b/uitest/src/com/vaadin/tests/tb3/TB3Runner.java @@ -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) { diff --git a/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java b/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java index 26fef667cd..e9ef11957c 100644 --- a/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java +++ b/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java @@ -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()); } /** |