Repository: tapestry-5 Updated Branches: refs/heads/master b993e79eb -> bf258ea96
Upgrade Selenium and Geb Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/bf258ea9 Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/bf258ea9 Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/bf258ea9 Branch: refs/heads/master Commit: bf258ea96be8645d2563eb5c8af047aac6325313 Parents: b993e79 Author: Jochen Kemnade <[email protected]> Authored: Fri Mar 3 11:03:54 2017 +0100 Committer: Jochen Kemnade <[email protected]> Committed: Tue Oct 10 08:30:49 2017 +0200 ---------------------------------------------------------------------- build.gradle | 4 +- .../integration/app1/AjaxGroovyTests.groovy | 6 +- .../integration/app1/AlertsTests.groovy | 6 +- .../integration/appfolder/AppFolderTests.groovy | 8 +- .../integration/app1/CoreBehaviorsTests.java | 13 ++- .../tapestry5/integration/app1/FormTests.java | 43 ++++---- .../integration/app1/PaletteTests.java | 6 +- .../integration/cluster/ClusterTests.java | 20 ++-- tapestry-test/build.gradle | 11 +- .../apache/tapestry5/test/SeleniumTestCase.java | 101 +++++++++++++------ tapestry-webresources/build.gradle | 2 + .../webresources/tests/WebResourcesSpec.groovy | 6 +- .../src/test/resources/GebConfig.groovy | 3 + 13 files changed, 146 insertions(+), 83 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bf258ea9/build.gradle ---------------------------------------------------------------------- diff --git a/build.gradle b/build.gradle index e0a8184..603ad17 100755 --- a/build.gradle +++ b/build.gradle @@ -16,8 +16,8 @@ project.ext.versions = [ spock: "1.0-groovy-2.4", hibernate: "5.1.0.Final", slf4j: "1.7.24", - geb: "0.13.1", - selenium: "2.53.1" + geb: "1.1.1", + selenium: "3.6.0" ] ext.continuousIntegrationBuild = Boolean.getBoolean("ci") http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bf258ea9/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AjaxGroovyTests.groovy ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AjaxGroovyTests.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AjaxGroovyTests.groovy index b4531da..209281a 100644 --- a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AjaxGroovyTests.groovy +++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AjaxGroovyTests.groovy @@ -1,5 +1,6 @@ package org.apache.tapestry5.integration.app1 +import org.openqa.selenium.By import org.testng.annotations.Test @@ -10,9 +11,8 @@ class AjaxGroovyTests extends App1TestCase { void radio_buttons_in_ajax_form() { openLinks "Ajax Radio Demo" - - click "css=label:contains('It')" - click "css=label:contains('Temp')" + webDriver.findElements(By.cssSelector('label')).find{it.text.contains('It')}.click() + webDriver.findElements(By.cssSelector('label')).find{it.text.contains('Temp')}.click() click SUBMIT http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bf258ea9/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AlertsTests.groovy ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AlertsTests.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AlertsTests.groovy index 081445b..92854f7 100644 --- a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AlertsTests.groovy +++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AlertsTests.groovy @@ -12,6 +12,7 @@ package org.apache.tapestry5.integration.app1 +import org.openqa.selenium.By import org.testng.annotations.Test /** @@ -82,8 +83,9 @@ class AlertsTests extends App1TestCase { assertTextPresent "trad warn transient" // dismiss the first alert that indicates the submission type - - click "css=$CONTAINER :contains('Traditional form submission') button.close" + webDriver.findElements(By.cssSelector(CONTAINER)).find{ + it.text.contains('Traditional form submission') + }.findElement(By.cssSelector('button.close')).click() // wait for the transient alert to be automatically removed sleep 5000 http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bf258ea9/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/appfolder/AppFolderTests.groovy ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/appfolder/AppFolderTests.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/appfolder/AppFolderTests.groovy index 0ee69ba..4a3c996 100644 --- a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/appfolder/AppFolderTests.groovy +++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/appfolder/AppFolderTests.groovy @@ -15,7 +15,7 @@ class AppFolderTests extends GroovyTapestryCoreTestCase @Test void page_navigation() { - openLinks "t5app/" + openLinks "t5app/ " assertTitle "Index Page" @@ -31,7 +31,7 @@ class AppFolderTests extends GroovyTapestryCoreTestCase @Test void component_event_request() { - openLinks "t5app/", "show index page alert" + openLinks "t5app/ ", "show index page alert" assertTextPresent "index page alert" } @@ -39,7 +39,7 @@ class AppFolderTests extends GroovyTapestryCoreTestCase @Test void static_pages() { - openLinks "static.html" + openLinks "static.html " assertTitle "Static File" @@ -51,7 +51,7 @@ class AppFolderTests extends GroovyTapestryCoreTestCase @Test void asset_access() { - openLinks "t5app/" + openLinks "t5app/ " // Ony one image on page String assetURL = getAttribute("//img/@src") http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bf258ea9/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java index fc71c69..fbe83c5 100644 --- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java +++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java @@ -14,6 +14,8 @@ package org.apache.tapestry5.integration.app1; import org.apache.tapestry5.corelib.mixins.RenderDisabled; import org.apache.tapestry5.integration.app1.pages.RenderErrorDemo; +import org.openqa.selenium.By; +import org.openqa.selenium.support.ui.ExpectedConditions; import org.testng.annotations.Test; public class CoreBehaviorsTests extends App1TestCase @@ -139,10 +141,10 @@ public class CoreBehaviorsTests extends App1TestCase openLinks("Expressions in JS Functions Demo"); click("button1"); - waitForCondition("selenium.getValue('target') == 'test1'", PAGE_LOAD_TIMEOUT); + waitForCondition(ExpectedConditions.attributeToBe(By.id("target"), "value", "test1")); click("button2"); - waitForCondition("selenium.getValue('target') == '{key=test2}'", PAGE_LOAD_TIMEOUT); + waitForCondition(ExpectedConditions.attributeToBe(By.id("target"), "value", "{key=test2}")); } @@ -1732,8 +1734,11 @@ public class CoreBehaviorsTests extends App1TestCase openLinks("Reload on nested page"); assertTextPresent("This page throws an exception"); - - clickAndWait("css=a:contains('Go to page'):contains('with reload')"); + + webDriver.findElements(By.cssSelector("a")).stream().filter((element) -> { + String text = element.getText(); + return text.contains("Go to page") && text.contains("with reload"); + }).findFirst().get().click(); assertTextPresent("This page throws an exception"); } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bf258ea9/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java index 2f6588a..b666012 100644 --- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java +++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java @@ -12,12 +12,15 @@ package org.apache.tapestry5.integration.app1; -import org.apache.tapestry5.corelib.components.Form; -import org.testng.annotations.Test; - import java.text.SimpleDateFormat; import java.util.Date; +import org.apache.tapestry5.corelib.components.Form; +import org.openqa.selenium.By; +import org.openqa.selenium.support.ui.ExpectedCondition; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.testng.annotations.Test; + /** * Tests for the {@link Form} component as well as many form control components. */ @@ -259,7 +262,9 @@ public class FormTests extends App1TestCase click("css=.x-impact .btn"); - waitForCSSSelectedElementToAppear("div.datePicker"); + ExpectedCondition datePickerVisible = ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.datePicker")); + + waitForCondition(datePickerVisible); assertEquals(getText("css=td.selected"), "28"); //move to the next month. @@ -294,7 +299,7 @@ public class FormTests extends App1TestCase //#3 click("css=.x-impact .btn"); - waitForCSSSelectedElementToAppear("div.datePicker"); + waitForCondition(datePickerVisible); click("css=div.datePicker .footerTable button"); waitForInvisible(pickerGoneSelector); @@ -304,7 +309,7 @@ public class FormTests extends App1TestCase //#2... click("css=.x-impact .btn"); - waitForCSSSelectedElementToAppear("div.datePicker"); + waitForCondition(datePickerVisible); click("css=button.nextButton"); waitForSelectedToBeRemoved(); @@ -321,7 +326,7 @@ public class FormTests extends App1TestCase click("css=.x-impact .btn"); - waitForCSSSelectedElementToAppear("div.datePicker"); + waitForCondition(datePickerVisible); String noneButton = "//button[text()='None']"; @@ -333,7 +338,7 @@ public class FormTests extends App1TestCase click("css=.x-impact .btn"); - waitForCSSSelectedElementToAppear("div.datePicker"); + waitForCondition(datePickerVisible); assertFalse(isElementPresent("css=td.selected")); click(noneButton); @@ -356,7 +361,10 @@ public class FormTests extends App1TestCase type("asteroidImpact", "05/28/2046"); click("css=.x-impact .btn"); - waitForCSSSelectedElementToAppear("div.datePicker"); + + ExpectedCondition datePickerVisible = ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.datePicker")); + + waitForCondition(datePickerVisible); click("css=.x-impact .btn"); waitForInvisible("css=div.datePicker"); @@ -364,19 +372,19 @@ public class FormTests extends App1TestCase //make sure that clicking somewhere outside the date picker //closes it click("css=.x-impact .btn"); - waitForCSSSelectedElementToAppear("div.datePicker"); + waitForCondition(datePickerVisible); click("css=h1"); waitForInvisible("css=div.datePicker"); //also make sure that clicking the month label /doesn't/ close the picker click("css=.x-impact .btn"); - waitForCSSSelectedElementToAppear("div.datePicker"); + waitForCondition(datePickerVisible); click("css=a.topLabel"); waitForCSSSelectedElementToAppear("div.labelPopup"); click("css=div.labelPopup a"); - waitForCondition("!selenium.isElementPresent('css=div.labelPopup')", PAGE_LOAD_TIMEOUT); + waitForInvisible("css=div.labelPopup"); //It's basically impossible to express "wait until the popup doesn't disappear" //Instead, we take advantage of knowing that the datepicker disappears with this bug /almost/ //immediately after picking the month label, so we sleep the test for a few seconds to provide @@ -438,26 +446,25 @@ public class FormTests extends App1TestCase String update = SUBMIT; - click("css=label:contains('Accounting')"); - + webDriver.findElements(By.cssSelector("label")).stream().filter(element-> element.getText().contains("Accounting")).findFirst().get().click(); clickAndWait(update); assertTextPresent("Selected department: ACCOUNTING"); - click("css=label:contains('Sales And Marketing')"); + webDriver.findElements(By.cssSelector("label")).stream().filter(element-> element.getText().contains("Sales And Marketin")).findFirst().get().click(); clickAndWait(update); assertTextPresent("Selected department: SALES_AND_MARKETING"); // not in a loop ... - click("css=label:contains('Temp')"); + webDriver.findElements(By.cssSelector("label")).stream().filter(element-> element.getText().contains("Temp")).findFirst().get().click(); clickAndWait(update); assertTextPresent("Selected position: TEMP"); - click("css=label:contains('Lifer')"); + webDriver.findElements(By.cssSelector("label")).stream().filter(element-> element.getText().contains("Lifer")).findFirst().get().click(); clickAndWait(update); @@ -508,7 +515,7 @@ public class FormTests extends App1TestCase assertAttribute(locator, "disabled"); } - assertAttribute("css=div.palette .btn@disabled", "disabled"); + assertAttribute("css=div.palette .btn@disabled", "true"); //TAP5-2078 clickAndWait("//input[@value='Continue']"); http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bf258ea9/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/PaletteTests.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/PaletteTests.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/PaletteTests.java index 4645637..23553e1 100644 --- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/PaletteTests.java +++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/PaletteTests.java @@ -15,6 +15,8 @@ package org.apache.tapestry5.integration.app1; import org.apache.tapestry5.corelib.components.Palette; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebElement; import org.testng.annotations.Test; /** @@ -111,7 +113,9 @@ public class PaletteTests extends App1TestCase * it is possible to get into this state by creating a model with * disabled options. */ - getEval("this.browserbot.findElement('" + AVAILABLE_OPTIONS + " option').disabled = 'disabled';"); + WebElement option = webDriver.findElement(convertLocator(AVAILABLE_OPTIONS+" option")); + JavascriptExecutor js = (JavascriptExecutor) webDriver; + js.executeScript("arguments[0].disabled = 'disabled'", option); // causes an error in the js console but does not throw an exception // here. optimally, this would make the test case fail. http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bf258ea9/tapestry-core/src/test/java/org/apache/tapestry5/integration/cluster/ClusterTests.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/cluster/ClusterTests.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/cluster/ClusterTests.java index 4670aaf..30575af 100644 --- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/cluster/ClusterTests.java +++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/cluster/ClusterTests.java @@ -16,6 +16,10 @@ package org.apache.tapestry5.integration.cluster; import com.thoughtworks.selenium.DefaultSelenium; import com.thoughtworks.selenium.Selenium; +import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium; + +import io.github.bonigarcia.wdm.FirefoxDriverManager; + import org.apache.tapestry5.test.JettyRunner; import org.apache.tapestry5.test.TapestryTestConstants; import org.eclipse.jetty.server.Server; @@ -23,8 +27,7 @@ import org.eclipse.jetty.server.session.JDBCSessionIdManager; import org.eclipse.jetty.server.session.JDBCSessionManager; import org.eclipse.jetty.server.session.SessionHandler; import org.eclipse.jetty.webapp.WebAppContext; -import org.openqa.selenium.server.RemoteControlConfiguration; -import org.openqa.selenium.server.SeleniumServer; +import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -67,7 +70,6 @@ public class ClusterTests JettyRunner serverB; - SeleniumServer seleniumServer; Selenium selenium; @BeforeClass @@ -78,16 +80,11 @@ public class ClusterTests serverA = configureClusteredJetty(SERVER_A_NAME, SERVER_A_PORT); serverB = configureClusteredJetty(SERVER_B_NAME, SERVER_B_PORT); - seleniumServer = new SeleniumServer(); - seleniumServer.start(); + FirefoxDriverManager.getInstance().setup(); + FirefoxDriver driver = new FirefoxDriver(); - String browserStartCommand = xmlTest.getParameter(TapestryTestConstants.BROWSER_START_COMMAND_PARAMETER); - browserStartCommand = browserStartCommand != null ? browserStartCommand : FIREFOX_BROWSER_CMD; + selenium = new WebDriverBackedSelenium(driver, "http://localhost:9091/"); - selenium = new DefaultSelenium( - "localhost", RemoteControlConfiguration.DEFAULT_PORT, - browserStartCommand, "http://localhost:9091/" - ); selenium.start(); } @@ -97,7 +94,6 @@ public class ClusterTests serverA.stop(); serverB.stop(); selenium.stop(); - seleniumServer.stop(); } @Test http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bf258ea9/tapestry-test/build.gradle ---------------------------------------------------------------------- diff --git a/tapestry-test/build.gradle b/tapestry-test/build.gradle index 7b7a1e2..f0dc96d 100644 --- a/tapestry-test/build.gradle +++ b/tapestry-test/build.gradle @@ -5,12 +5,13 @@ dependencies { compile project(":tapestry-test-data") compile project(":tapestry-runner") - compile "org.seleniumhq.selenium:selenium-java:${versions.selenium}", { - exclude group: "org.eclipse.jetty" - } - compile "org.seleniumhq.selenium:selenium-server:${versions.selenium}", { - exclude group: "org.eclipse.jetty" + compile ("io.github.bonigarcia:webdrivermanager:1.7.2") + + compile "org.seleniumhq.selenium:selenium-leg-rc:${versions.selenium}", { + exclude group: "org.seleniumhq.selenium", module: "jetty-repacked" + exclude group: "org.testng", module: "testng" } + compile "org.seleniumhq.selenium:selenium-support:${versions.selenium}" compile "org.testng:testng:${versions.testng}" compile "org.easymock:easymock:${versions.easymock}" http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bf258ea9/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java ---------------------------------------------------------------------- diff --git a/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java b/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java index 55a9602..9b57b85 100644 --- a/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java +++ b/tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java @@ -13,10 +13,26 @@ package org.apache.tapestry5.test; import com.thoughtworks.selenium.CommandProcessor; -import com.thoughtworks.selenium.DefaultSelenium; import com.thoughtworks.selenium.HttpCommandProcessor; import com.thoughtworks.selenium.Selenium; -import org.openqa.selenium.server.SeleniumServer; +import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium; +import com.thoughtworks.selenium.webdriven.WebDriverCommandProcessor; + +import io.github.bonigarcia.wdm.FirefoxDriverManager; + +import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.firefox.FirefoxOptions; +import org.openqa.selenium.firefox.FirefoxProfile; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.internal.WrapsDriver; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.ExpectedCondition; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.Assert; @@ -26,6 +42,7 @@ import org.testng.xml.XmlTest; import java.io.File; import java.lang.reflect.Method; +import java.util.concurrent.TimeUnit; /** * Base class for creating Selenium-based integration test cases. This class implements all the @@ -63,8 +80,11 @@ public abstract class SeleniumTestCase extends Assert implements Selenium * * @since 5.3 */ + @Deprecated protected Selenium selenium; + protected WebDriver webDriver; + private String baseURL; private ErrorReporter errorReporter; @@ -190,29 +210,32 @@ public abstract class SeleniumTestCase extends Assert implements Selenium final Runnable stopWebServer = launchWebServer(container, webAppFolder, contextPath, port, sslPort); - final SeleniumServer seleniumServer = new SeleniumServer(); + FirefoxDriverManager.getInstance().setup(); File ffProfileTemplate = new File(TapestryRunnerConstants.MODULE_BASE_DIR, "src/test/conf/ff_profile_template"); + DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox(); + desiredCapabilities.setCapability(FirefoxDriver.MARIONETTE, false); + + FirefoxOptions options = new FirefoxOptions(desiredCapabilities); if (ffProfileTemplate.isDirectory()) { - seleniumServer.getConfiguration().setFirefoxProfileTemplate(ffProfileTemplate); + FirefoxProfile profile = new FirefoxProfile(ffProfileTemplate); + options.setProfile(profile); } - seleniumServer.start(); + FirefoxDriver driver = new FirefoxDriver(options); + driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); + CommandProcessor webDriverCommandProcessor = new WebDriverCommandProcessor(baseURL, driver); - CommandProcessor httpCommandProcessor = new HttpCommandProcessor("localhost", - seleniumServer.getPort(), browserStartCommand, baseURL); - final ErrorReporterImpl errorReporter = new ErrorReporterImpl(httpCommandProcessor, testContext); + final ErrorReporterImpl errorReporter = new ErrorReporterImpl(webDriverCommandProcessor, testContext); - ErrorReportingCommandProcessor commandProcessor = new ErrorReportingCommandProcessor(httpCommandProcessor, + ErrorReportingCommandProcessor commandProcessor = new ErrorReportingCommandProcessor(webDriverCommandProcessor, errorReporter); - final Selenium selenium = new DefaultSelenium(commandProcessor); - - selenium.start(); + Selenium selenium = new WebDriverBackedSelenium(driver, baseURL); testContext.setAttribute(TapestryTestConstants.BASE_URL_ATTRIBUTE, baseURL); testContext.setAttribute(TapestryTestConstants.SELENIUM_ATTRIBUTE, selenium); @@ -238,14 +261,6 @@ public abstract class SeleniumTestCase extends Assert implements Selenium LOGGER.info("Shutting down selenium server ..."); - try - { - seleniumServer.stop(); - } catch (RuntimeException e) - { - LOGGER.error("Selenium server shutdown failure.", e); - } - LOGGER.info("Shutting web server ..."); try @@ -362,6 +377,7 @@ public abstract class SeleniumTestCase extends Assert implements Selenium this.testContext = context; selenium = (Selenium) context.getAttribute(TapestryTestConstants.SELENIUM_ATTRIBUTE); + webDriver = ((WrapsDriver) selenium).getWrappedDriver(); baseURL = (String) context.getAttribute(TapestryTestConstants.BASE_URL_ATTRIBUTE); errorReporter = (ErrorReporter) context.getAttribute(TapestryTestConstants.ERROR_REPORTER_ATTRIBUTE); } @@ -533,7 +549,9 @@ public abstract class SeleniumTestCase extends Assert implements Selenium @Override public void click(String locator) { - selenium.click(locator); + WebElement element = webDriver.findElement(convertLocator(locator)); + ((JavascriptExecutor) webDriver).executeScript("arguments[0].scrollIntoView(true);", element); + element.click(); } @Override @@ -1316,6 +1334,12 @@ public abstract class SeleniumTestCase extends Assert implements Selenium selenium.waitForCondition(script, timeout); } + protected void waitForCondition(ExpectedCondition condition) + { + WebDriverWait wait = new WebDriverWait(webDriver, 10); + wait.until(condition); + } + @Override public void waitForFrameToLoad(String frameAddress, String timeout) { @@ -1516,7 +1540,6 @@ public abstract class SeleniumTestCase extends Assert implements Selenium protected final void clickAndWait(String locator) { click(locator); - waitForPageToLoad(); } @@ -1675,9 +1698,7 @@ public abstract class SeleniumTestCase extends Assert implements Selenium */ protected final void waitForVisible(String selector) { - String condition = String.format("selenium.isVisible(\"%s\")", selector); - - waitForCondition(condition, PAGE_LOAD_TIMEOUT); + waitForCondition(ExpectedConditions.visibilityOfElementLocated(convertLocator(selector))); } /** @@ -1691,9 +1712,7 @@ public abstract class SeleniumTestCase extends Assert implements Selenium */ protected final void waitForInvisible(String selector) { - String condition = String.format("!selenium.isVisible(\"%s\")", selector); - - waitForCondition(condition, PAGE_LOAD_TIMEOUT); + waitForCondition(ExpectedConditions.invisibilityOfElementLocated(convertLocator(selector))); } /** @@ -1767,4 +1786,28 @@ public abstract class SeleniumTestCase extends Assert implements Selenium return selenium.getCssCount(str); } -} + protected static By convertLocator(String locator) + { + By by; + if (locator.startsWith("link=")) + { + return By.linkText(locator.substring(5)); + } + else if (locator.startsWith("css=")) + { + return By.cssSelector(locator.substring(4)); + } + else if (locator.startsWith("xpath=")) + { + return By.xpath(locator.substring(6)); + } + else if (locator.startsWith("//")) + { + return By.xpath(locator); + } + else + { + return By.id(locator); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bf258ea9/tapestry-webresources/build.gradle ---------------------------------------------------------------------- diff --git a/tapestry-webresources/build.gradle b/tapestry-webresources/build.gradle index 28b6466..fa24be1 100644 --- a/tapestry-webresources/build.gradle +++ b/tapestry-webresources/build.gradle @@ -15,6 +15,8 @@ dependencies { testCompile "org.seleniumhq.selenium:selenium-server:${versions.selenium}", { exclude group: "org.eclipse.jetty" } + testCompile ("io.github.bonigarcia:webdrivermanager:1.7.2") + } jar.manifest { http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bf258ea9/tapestry-webresources/src/test/groovy/t5/webresources/tests/WebResourcesSpec.groovy ---------------------------------------------------------------------- diff --git a/tapestry-webresources/src/test/groovy/t5/webresources/tests/WebResourcesSpec.groovy b/tapestry-webresources/src/test/groovy/t5/webresources/tests/WebResourcesSpec.groovy index 2d4b52c..392db86 100644 --- a/tapestry-webresources/src/test/groovy/t5/webresources/tests/WebResourcesSpec.groovy +++ b/tapestry-webresources/src/test/groovy/t5/webresources/tests/WebResourcesSpec.groovy @@ -27,7 +27,7 @@ class WebResourcesSpec extends GebReportingSpec { // Open index page go() - waitFor { !$("body[data-page-initialized]").empty } + waitFor { $('body').@'data-page-initialized' == 'true' } then: @@ -42,7 +42,7 @@ class WebResourcesSpec extends GebReportingSpec { go() - waitFor { !$("body[data-page-initialized]").empty } + waitFor { $('body').@'data-page-initialized' == 'true' } // Because the CoffeeScript may already be pre-compiled, it can outrace the Less compilation. // For some reason, the navbar is invisible (at least to Selenium) until the CSS loads. @@ -57,6 +57,6 @@ class WebResourcesSpec extends GebReportingSpec { then: - $(".demo").css("background-color") == "rgba(179, 179, 255, 1)" + $(".demo").css("background-color") == "rgb(179, 179, 255)" } } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bf258ea9/tapestry-webresources/src/test/resources/GebConfig.groovy ---------------------------------------------------------------------- diff --git a/tapestry-webresources/src/test/resources/GebConfig.groovy b/tapestry-webresources/src/test/resources/GebConfig.groovy index a620554..a45863a 100644 --- a/tapestry-webresources/src/test/resources/GebConfig.groovy +++ b/tapestry-webresources/src/test/resources/GebConfig.groovy @@ -1,6 +1,9 @@ +import io.github.bonigarcia.wdm.FirefoxDriverManager + driver = "firefox" baseUrl = "http://localhost:8080" +FirefoxDriverManager.getInstance().setup(); waiting { // Long timeout since we have to wait for Rhino & friends to spin up
