From 5573a2525ce166d71610a325a8fbafde0ea55ec6 Mon Sep 17 00:00:00 2001 From: Mark Collin Date: Fri, 26 Feb 2016 07:55:40 +0000 Subject: [PATCH] Update template to use latest library and plugin versions. Add Marionette configuration --- .gitignore | 9 +- README.md | 20 ++-- pom.xml | 14 ++- .../com/lazerycode/selenium/DriverBase.java | 48 ++++++++ .../lazerycode/selenium/DriverFactory.java | 48 -------- ...ebDriverThread.java => DriverFactory.java} | 2 +- .../selenium/config/DriverType.java | 3 + .../listeners/ScreenshotListener.java | 2 +- .../selenium/tests/GoogleExampleIT.java | 4 +- src/test/resources/RepositoryMap.xml | 107 ++++++++++++------ 10 files changed, 150 insertions(+), 107 deletions(-) create mode 100644 src/test/java/com/lazerycode/selenium/DriverBase.java delete mode 100644 src/test/java/com/lazerycode/selenium/DriverFactory.java rename src/test/java/com/lazerycode/selenium/config/{WebDriverThread.java => DriverFactory.java} (99%) diff --git a/.gitignore b/.gitignore index 7a0a9d72..a65eab69 100644 --- a/.gitignore +++ b/.gitignore @@ -26,13 +26,6 @@ *.sql *.sqlite -# OS generated files # -###################### -.DS_Store* -ehthumbs.db -Icon? -Thumbs.db - # IntelliJ # ############ *.iml @@ -54,5 +47,5 @@ Thumbs.db # Binary Downloads # #################### -**/selenium_standalone_binaries/ +**/selenium_standalone/ **/selenium_standalone_zips/ \ No newline at end of file diff --git a/README.md b/README.md index 8be1ac8f..bb2b4d76 100644 --- a/README.md +++ b/README.md @@ -8,15 +8,19 @@ A maven template for Selenium that has the latest dependencies so that you can j 1. Open a terminal window/command prompt 2. Clone this project. -3. CD into project directory -4. mvn clean verify +3. `cd Selenium-Maven-Template` (Or whatever folder you cloned it into) +4. `mvn clean verify` All dependencies should now be downloaded and the example google cheese test will have run successfully (Assuming you have Firefox installed in the default location) ### What should I know? -- To run any unit tests that test your Selenium framework you just need to ensure that all unit test file names end, or start with "test" and they will be run by step 4. -- The maven surefire plugin has been used to create a profile with the id "selenium-tests" that configures surefire to pick up any java files that ends with the text "WebDriver". This means that as long as all of your selenium test file names end with WebDriver.java they will get picked up and run when you perform step 4. +- To run any unit tests that test your Selenium framework you just need to ensure that all unit test file names end, or start with "test" and they will be run as part of the build. +- The maven failsafe plugin has been used to create a profile with the id "selenium-tests". This is active by default, but if you want to perform a build without running your selenium tests you can disable it using: + + mvn clean verify -P-selenium-tests + +- The maven-failsafe-plugin will pick up any files that end in IT by default. You can customise this is you would prefer to use a custom identifier for your Selenium tests. ### Anything else? @@ -29,7 +33,7 @@ Yes you can specify which browser to use by using one of the following switches: - -Dbrowser=htmlunit - -Dbrowser=phantomjs -You don't need to worry about downloading the IEDriverServer, or chromedriver binaries, this project will do that for you automatically. +You don't need to worry about downloading the IEDriverServer, chromedriver , operachromium, or wires binaries, this project will do that for you automatically. Not got PhantomJS? Don't worry that will be automatically downloaded for you as well! @@ -39,7 +43,7 @@ You can specify a grid to connect to where you can choose your browser, browser - -DseleniumGridURL=http://{username}:{accessKey}@ondemand.saucelabs.com:80/wd/hub - -Dplatform=xp - -Dbrowser=firefox -- -DbrowserVersion=33 +- -DbrowserVersion=44 You can even specify multiple threads (you can do it on a grid as well!): @@ -61,5 +65,5 @@ If you need to force a binary overwrite you can do: You have probably got outdated driver binaries, by default they are not overwritten if they already exist to speed things up. You have two options: -- mvn clean verify -Doverwrite.binaries=true -- Delete the selenium_standalone_binaries folder in your resources directory \ No newline at end of file +- `mvn clean verify -Doverwrite.binaries=true` +- Delete the `selenium_standalone_binaries` folder in your resources directory \ No newline at end of file diff --git a/pom.xml b/pom.xml index c37b1bf7..7a4b92d8 100644 --- a/pom.xml +++ b/pom.xml @@ -40,7 +40,7 @@ UTF-8 UTF-8 - 2.48.2 + 2.52.0 false firefox 1 @@ -79,7 +79,7 @@ org.testng testng - 6.9.8 + 6.9.10 test @@ -99,14 +99,14 @@ 1.7 1.7 - 2.3.2 + 3.5.1 com.lazerycode.selenium driver-binary-downloader-maven-plugin - 1.0.7 + 1.0.9 - ${standalone.binary.root.folder} + ${project.basedir}/src/test/resources/selenium_standalone_binaries ${project.basedir}/src/test/resources/selenium_standalone_zips ${project.basedir}/src/test/resources/RepositoryMap.xml ${overwrite.binaries} @@ -122,7 +122,7 @@ org.apache.maven.plugins maven-failsafe-plugin - 2.18.1 + 2.19.1 methods ${threads} @@ -142,12 +142,14 @@ ${webdriver.chrome.driver} ${webdriver.ie.driver} ${webdriver.opera.driver} + ${webdriver.gecko.driver} integration-test + verify diff --git a/src/test/java/com/lazerycode/selenium/DriverBase.java b/src/test/java/com/lazerycode/selenium/DriverBase.java new file mode 100644 index 00000000..d8657c7c --- /dev/null +++ b/src/test/java/com/lazerycode/selenium/DriverBase.java @@ -0,0 +1,48 @@ +package com.lazerycode.selenium; + +import com.lazerycode.selenium.config.DriverFactory; +import com.lazerycode.selenium.listeners.ScreenshotListener; +import org.openqa.selenium.WebDriver; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.AfterSuite; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Listeners; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +@Listeners(ScreenshotListener.class) +public class DriverBase { + + private static List webDriverThreadPool = Collections.synchronizedList(new ArrayList()); + private static ThreadLocal driverFactory; + + @BeforeSuite(alwaysRun = true) + public static void instantiateDriverObject() { + driverFactory = new ThreadLocal() { + @Override + protected DriverFactory initialValue() { + DriverFactory driverFactory = new DriverFactory(); + webDriverThreadPool.add(driverFactory); + return driverFactory; + } + }; + } + + public static WebDriver getDriver() throws Exception { + return driverFactory.get().getDriver(); + } + + @AfterMethod(alwaysRun = true) + public static void clearCookies() throws Exception { + getDriver().manage().deleteAllCookies(); + } + + @AfterSuite(alwaysRun = true) + public static void closeDriverObjects() { + for (DriverFactory driverFactory : webDriverThreadPool) { + driverFactory.quitDriver(); + } + } +} \ No newline at end of file diff --git a/src/test/java/com/lazerycode/selenium/DriverFactory.java b/src/test/java/com/lazerycode/selenium/DriverFactory.java deleted file mode 100644 index 8ad824c3..00000000 --- a/src/test/java/com/lazerycode/selenium/DriverFactory.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.lazerycode.selenium; - -import com.lazerycode.selenium.config.WebDriverThread; -import com.lazerycode.selenium.listeners.ScreenshotListener; -import org.openqa.selenium.WebDriver; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.AfterSuite; -import org.testng.annotations.BeforeSuite; -import org.testng.annotations.Listeners; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -@Listeners(ScreenshotListener.class) -public class DriverFactory { - - private static List webDriverThreadPool = Collections.synchronizedList(new ArrayList()); - private static ThreadLocal driverThread; - - @BeforeSuite - public static void instantiateDriverObject() { - driverThread = new ThreadLocal() { - @Override - protected WebDriverThread initialValue() { - WebDriverThread webDriverThread = new WebDriverThread(); - webDriverThreadPool.add(webDriverThread); - return webDriverThread; - } - }; - } - - public static WebDriver getDriver() throws Exception { - return driverThread.get().getDriver(); - } - - @AfterMethod - public static void clearCookies() throws Exception { - getDriver().manage().deleteAllCookies(); - } - - @AfterSuite - public static void closeDriverObjects() { - for (WebDriverThread webDriverThread : webDriverThreadPool) { - webDriverThread.quitDriver(); - } - } -} \ No newline at end of file diff --git a/src/test/java/com/lazerycode/selenium/config/WebDriverThread.java b/src/test/java/com/lazerycode/selenium/config/DriverFactory.java similarity index 99% rename from src/test/java/com/lazerycode/selenium/config/WebDriverThread.java rename to src/test/java/com/lazerycode/selenium/config/DriverFactory.java index d8fcbaa6..fe25ebcf 100644 --- a/src/test/java/com/lazerycode/selenium/config/WebDriverThread.java +++ b/src/test/java/com/lazerycode/selenium/config/DriverFactory.java @@ -13,7 +13,7 @@ import static com.lazerycode.selenium.config.DriverType.valueOf; import static org.openqa.selenium.Proxy.ProxyType.MANUAL; -public class WebDriverThread { +public class DriverFactory { private WebDriver webdriver; private DriverType selectedDriverType; diff --git a/src/test/java/com/lazerycode/selenium/config/DriverType.java b/src/test/java/com/lazerycode/selenium/config/DriverType.java index fc9f9b70..c8ce3b1b 100644 --- a/src/test/java/com/lazerycode/selenium/config/DriverType.java +++ b/src/test/java/com/lazerycode/selenium/config/DriverType.java @@ -23,6 +23,9 @@ public enum DriverType implements DriverSetup { FIREFOX { public DesiredCapabilities getDesiredCapabilities(Proxy proxySettings) { DesiredCapabilities capabilities = DesiredCapabilities.firefox(); + //TODO Uncomment the capability settings below to use Marionette +// capabilities.setCapability("marionette", true); +// capabilities.setCapability("binary", System.getProperty("webdriver.gecko.driver")); return addProxySettings(capabilities, proxySettings); } diff --git a/src/test/java/com/lazerycode/selenium/listeners/ScreenshotListener.java b/src/test/java/com/lazerycode/selenium/listeners/ScreenshotListener.java index 2bb2bef1..cb81fa5b 100644 --- a/src/test/java/com/lazerycode/selenium/listeners/ScreenshotListener.java +++ b/src/test/java/com/lazerycode/selenium/listeners/ScreenshotListener.java @@ -11,7 +11,7 @@ import java.io.FileOutputStream; import java.io.IOException; -import static com.lazerycode.selenium.DriverFactory.getDriver; +import static com.lazerycode.selenium.DriverBase.getDriver; public class ScreenshotListener extends TestListenerAdapter { diff --git a/src/test/java/com/lazerycode/selenium/tests/GoogleExampleIT.java b/src/test/java/com/lazerycode/selenium/tests/GoogleExampleIT.java index 0618622d..1e73869c 100644 --- a/src/test/java/com/lazerycode/selenium/tests/GoogleExampleIT.java +++ b/src/test/java/com/lazerycode/selenium/tests/GoogleExampleIT.java @@ -1,6 +1,6 @@ package com.lazerycode.selenium.tests; -import com.lazerycode.selenium.DriverFactory; +import com.lazerycode.selenium.DriverBase; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; @@ -8,7 +8,7 @@ import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.annotations.Test; -public class GoogleExampleIT extends DriverFactory { +public class GoogleExampleIT extends DriverBase { @Test public void googleCheeseExample() throws Exception { diff --git a/src/test/resources/RepositoryMap.xml b/src/test/resources/RepositoryMap.xml index e8e7076f..42e5ef6e 100644 --- a/src/test/resources/RepositoryMap.xml +++ b/src/test/resources/RepositoryMap.xml @@ -2,38 +2,50 @@ - + - http://selenium-release.storage.googleapis.com/2.45/IEDriverServer_x64_2.45.0.zip - b3cdacc846d7b9c3f8fb8b70af0a9cfc5839bd83 + http://selenium-release.storage.googleapis.com/2.52/IEDriverServer_x64_2.52.0.zip + c850d584bc647a52c1c1311c233c68d4ac9f1ac8 sha1 - http://selenium-release.storage.googleapis.com/2.45/IEDriverServer_Win32_2.45.0.zip - cc822d30efe3119b76af9265c47d42fca208f85a + http://selenium-release.storage.googleapis.com/2.52/IEDriverServer_Win32_2.52.0.zip + 55bbe45c5ebfdb66edc6502afd05a2342183ebb9 sha1 - + - http://chromedriver.storage.googleapis.com/2.14/chromedriver_win32.zip - 4fe4aaf625073c39c29da994d815ffcc2c314c40 + http://chromedriver.storage.googleapis.com/2.21/chromedriver_win32.zip + 2ee59a8047ec345f886d5b90656dbea1469b7e44 sha1 - - - https://github.com/operasoftware/operachromiumdriver/releases/download/v0.1.0/operadriver_win32.zip - 4a4ad051c315e4141048f0ae587c05f4c8720c24 + + + https://github.com/operasoftware/operachromiumdriver/releases/download/v0.2.2/operadriver_win64.zip + 8b84d334ca6dc5e30c168d8df080c1827e4c6fdb + sha1 + + + https://github.com/operasoftware/operachromiumdriver/releases/download/v0.2.2/operadriver_win32.zip + daa9ba52eeca5ea3cb8a9020b85642ec047e9890 sha1 + + + https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.0.0-windows.zip + ca0c753e5d8820a271dd7c2d6a9fad6ff86fb09f + sha1 + + https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-windows.zip @@ -42,32 +54,41 @@ + + + + https://github.com/jgraham/wires/releases/download/v0.6.2/wires-0.6.2-win.zip + 20a0eca607edd98392e0590a5a307ef56526647e + sha1 + + + - + - http://chromedriver.storage.googleapis.com/2.14/chromedriver_linux64.zip - acb76a3eb2bc94ee96b6a17121980e2662c88650 + http://chromedriver.storage.googleapis.com/2.21/chromedriver_linux64.zip + 7be5d5c58fa826147aa83aa61c7fb0d8ca94805b sha1 - http://chromedriver.storage.googleapis.com/2.14/chromedriver_linux32.zip - 237a5ed160bb23118a9ea5b84700e8799e897bd4 + http://chromedriver.storage.googleapis.com/2.21/chromedriver_linux32.zip + f783f76e06db305f10df0d307abc4ab3e9b0d998 sha1 - + - https://github.com/operasoftware/operachromiumdriver/releases/download/v0.1.0/operadriver_linux32.zip - feda76d61190161bd9923f8f1613447f722f12fc + https://github.com/operasoftware/operachromiumdriver/releases/download/v0.2.2/operadriver_linux32.zip + 8b0b92a870a1b4ba619eb0b85ec587caa2942e5b sha1 - https://github.com/operasoftware/operachromiumdriver/releases/download/v0.1.0/operadriver_linux64.zip - c36234222efccc1f874682b2ce2add639d544e9d + https://github.com/operasoftware/operachromiumdriver/releases/download/v0.2.2/operadriver_linux64.zip + c207c6916e20ecbbc7157e3bdeb4737f14f15fe3 sha1 @@ -86,32 +107,43 @@ + + + + https://github.com/jgraham/wires/releases/download/v0.6.2/wires-0.6.2-linux64.gz + 0adc84131607057ca37d42426798bff99faafb56 + sha1 + + + - + - http://chromedriver.storage.googleapis.com/2.14/chromedriver_mac32.zip - 64ef44893a87a0e470b60ff8f5fc83a588b78023 + http://chromedriver.storage.googleapis.com/2.21/chromedriver_mac32.zip + 49afcd80ab445c3085f8012180f7579b90afb364 sha1 - - - https://github.com/operasoftware/operachromiumdriver/releases/download/v0.1.0/operadriver_mac32.zip - 7ab79a1c70bb0f5998b9c5c8d08160ef86b618e9 - sha1 - + - https://github.com/operasoftware/operachromiumdriver/releases/download/v0.1.0/operadriver_mac64.zip - 32e5e0fc63bed0f61bb4e8695fd7a8faaebd7b37 + https://github.com/operasoftware/operachromiumdriver/releases/download/v0.2.2/operadriver_mac64.zip + d58a3b676dda7ede5c38e5df218e7c619495c4ed sha1 + + + https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.0.0-macosx.zip + 97f87188bb2fc81e0c57ec3a376b722e3bcc30c9 + sha1 + + https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-macosx.zip @@ -120,5 +152,14 @@ + + + + https://github.com/jgraham/wires/releases/download/v0.6.2/wires-0.6.2-OSX.gz + 2efc475bcc736d0502fb09051932e63052e98c4e + sha1 + + + \ No newline at end of file