Skip to content

Commit

Permalink
Update template to use latest library and plugin versions.
Browse files Browse the repository at this point in the history
Add Marionette configuration
  • Loading branch information
Ardesco committed Feb 26, 2016
1 parent 104a703 commit 5573a25
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 107 deletions.
9 changes: 1 addition & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@
*.sql
*.sqlite

# OS generated files #
######################
.DS_Store*
ehthumbs.db
Icon?
Thumbs.db

# IntelliJ #
############
*.iml
Expand All @@ -54,5 +47,5 @@ Thumbs.db

# Binary Downloads #
####################
**/selenium_standalone_binaries/
**/selenium_standalone/
**/selenium_standalone_zips/
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand All @@ -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!

Expand All @@ -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!):

Expand All @@ -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
- `mvn clean verify -Doverwrite.binaries=true`
- Delete the `selenium_standalone_binaries` folder in your resources directory
14 changes: 8 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<selenium.version>2.48.2</selenium.version>
<selenium.version>2.52.0</selenium.version>
<overwrite.binaries>false</overwrite.binaries>
<browser>firefox</browser>
<threads>1</threads>
Expand Down Expand Up @@ -79,7 +79,7 @@
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.8</version>
<version>6.9.10</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -99,14 +99,14 @@
<source>1.7</source>
<target>1.7</target>
</configuration>
<version>2.3.2</version>
<version>3.5.1</version>
</plugin>
<plugin>
<groupId>com.lazerycode.selenium</groupId>
<artifactId>driver-binary-downloader-maven-plugin</artifactId>
<version>1.0.7</version>
<version>1.0.9</version>
<configuration>
<rootStandaloneServerDirectory>${standalone.binary.root.folder}</rootStandaloneServerDirectory>
<rootStandaloneServerDirectory>${project.basedir}/src/test/resources/selenium_standalone_binaries</rootStandaloneServerDirectory>
<downloadedZipFileDirectory>${project.basedir}/src/test/resources/selenium_standalone_zips</downloadedZipFileDirectory>
<customRepositoryMap>${project.basedir}/src/test/resources/RepositoryMap.xml</customRepositoryMap>
<overwriteFilesThatExist>${overwrite.binaries}</overwriteFilesThatExist>
Expand All @@ -122,7 +122,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<version>2.19.1</version>
<configuration>
<parallel>methods</parallel>
<threadCount>${threads}</threadCount>
Expand All @@ -142,12 +142,14 @@
<webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
<webdriver.ie.driver>${webdriver.ie.driver}</webdriver.ie.driver>
<webdriver.opera.driver>${webdriver.opera.driver}</webdriver.opera.driver>
<webdriver.gecko.driver>${webdriver.gecko.driver}</webdriver.gecko.driver>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<!--This goal makes the build fail if you have test failures-->
<goal>verify</goal>
</goals>
</execution>
Expand Down
48 changes: 48 additions & 0 deletions src/test/java/com/lazerycode/selenium/DriverBase.java
Original file line number Diff line number Diff line change
@@ -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<DriverFactory> webDriverThreadPool = Collections.synchronizedList(new ArrayList<DriverFactory>());
private static ThreadLocal<DriverFactory> driverFactory;

@BeforeSuite(alwaysRun = true)
public static void instantiateDriverObject() {
driverFactory = new ThreadLocal<DriverFactory>() {
@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();
}
}
}
48 changes: 0 additions & 48 deletions src/test/java/com/lazerycode/selenium/DriverFactory.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/com/lazerycode/selenium/config/DriverType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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;
import org.openqa.selenium.support.ui.ExpectedCondition;
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 {
Expand Down
Loading

0 comments on commit 5573a25

Please sign in to comment.