-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from geekdenz/master
Fix issue #9: Succeed build.
- Loading branch information
Showing
32 changed files
with
591 additions
and
749 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
/target | ||
settings.xml | ||
chromedriver | ||
geckodriver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
wget https://github.com/mozilla/geckodriver/releases/download/v0.18.0/geckodriver-v0.18.0-linux64.tar.gz | ||
tar xvfz geckodriver-v0.18.0-linux64.tar.gz | ||
rm geckodriver-v0.18.0-linux64.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,121 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>selenium-cucumber</groupId> | ||
<artifactId>selenium-cucumber-java</artifactId> | ||
<version>0.0.1</version> | ||
<packaging>jar</packaging> | ||
<name>selenium-cucumber-java</name> | ||
<groupId>selenium-cucumber</groupId> | ||
<artifactId>selenium-cucumber-java</artifactId> | ||
<version>0.1.3</version> | ||
<packaging>jar</packaging> | ||
<name>selenium-cucumber-java</name> | ||
|
||
<dependencies> | ||
<!-- These are the cucumber dependencies --> | ||
<dependency> | ||
<groupId>info.cukes</groupId> | ||
<artifactId>cucumber-java</artifactId> | ||
<version>1.2.5</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependencies> | ||
<!-- These are the cucumber dependencies --> | ||
<dependency> | ||
<groupId>info.cukes</groupId> | ||
<artifactId>cucumber-java</artifactId> | ||
<version>1.2.5</version> | ||
</dependency> | ||
|
||
<!-- These are the cucumber-junit dependencies --> | ||
<dependency> | ||
<groupId>info.cukes</groupId> | ||
<artifactId>cucumber-junit</artifactId> | ||
<version>1.2.5</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- These are the cucumber-junit dependencies --> | ||
<dependency> | ||
<groupId>info.cukes</groupId> | ||
<artifactId>cucumber-junit</artifactId> | ||
<version>1.2.5</version> | ||
</dependency> | ||
|
||
<!-- These are the junit dependencies --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- These are the selenium-webdriver dependencies --> | ||
<!-- These are the junit dependencies --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
</dependency> | ||
|
||
<!-- These are the selenium-webdriver dependencies --> | ||
<dependency> | ||
<groupId>org.seleniumhq.selenium</groupId> | ||
<artifactId>selenium-java</artifactId> | ||
<version>3.0.0</version> | ||
<version>3.5.3</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.seleniumhq.selenium</groupId> | ||
<artifactId>selenium-server</artifactId> | ||
<version>3.0.0</version> | ||
</dependency> | ||
|
||
<!-- These are the selenium-cucumber methods dependencies --> | ||
<groupId>org.seleniumhq.selenium</groupId> | ||
<artifactId>selenium-server</artifactId> | ||
<version>3.5.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>sample</groupId> | ||
<artifactId>com.sample</artifactId> | ||
<version>1.0.0</version> | ||
<type>jar</type> | ||
<scope>system</scope> | ||
<systemPath>${project.basedir}/src/main/resources/selenium-cucumber-methods-1.0.0.jar</systemPath> | ||
<groupId>org.seleniumhq.selenium</groupId> | ||
<artifactId>selenium-firefox-driver</artifactId> | ||
<version>3.5.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.seleniumhq.selenium</groupId> | ||
<artifactId>selenium-remote-driver</artifactId> | ||
<version>3.5.3</version> | ||
</dependency> | ||
|
||
<!-- These are the selenium-cucumber methods dependencies --> | ||
<dependency> | ||
<groupId>sample</groupId> | ||
<artifactId>com.sample</artifactId> | ||
<version>1.0.0</version> | ||
<type>jar</type> | ||
<scope>system</scope> | ||
<systemPath>${project.basedir}/src/main/resources/selenium-cucumber-methods-1.0.0.jar</systemPath> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
<version>21.0</version> | ||
</dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
<version>21.0</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.2</version> | ||
<configuration> | ||
<encoding>UTF-8</encoding> | ||
<source>1.7</source> | ||
<target>1.7</target> | ||
<compilerArgument>-Werror</compilerArgument> | ||
|
||
<systemPropertyVariables> | ||
<property> | ||
<name>browser</name> | ||
<value>${browser}</value> | ||
</property> | ||
<property> | ||
<name>cloud_config</name> | ||
<value>${cloud_config}</value> | ||
</property> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.2</version> | ||
<configuration> | ||
<encoding>UTF-8</encoding> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
<compilerArgument>-Werror</compilerArgument> | ||
|
||
<systemPropertyVariables> | ||
<property> | ||
<name>browser</name> | ||
<value>${browser}</value> | ||
</property> | ||
<property> | ||
<name>cloud_config</name> | ||
<value>${cloud_config}</value> | ||
</property> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<!-- | ||
<distributionManagement> | ||
<repository> | ||
<id>bintray-geekdenz-landcare-selenium-cucumber-java</id> | ||
<name>geekdenz-selenium-cucumber-java</name> | ||
<url>https://api.bintray.com/maven/geekdenz/landcare/selenium-cucumber-java/;publish=1</url> | ||
</repository> | ||
</distributionManagement> | ||
--> | ||
<distributionManagement> | ||
<repository> | ||
<id>bintray-geekdenz-maven-selenium-cucumber-java</id> | ||
<name>geekdenz-selenium-cucumber-java</name> | ||
<url>https://api.bintray.com/maven/geekdenz/maven/selenium-cucumber-java/;publish=1</url> | ||
</repository> | ||
<snapshotRepository> | ||
<id>bintray-geekdenz-maven-selenium-cucumber-java</id> <!-- same id with the server in settings.xml --> | ||
<name>oss-jfrog-artifactory-snapshots</name> | ||
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local</url> | ||
</snapshotRepository> | ||
</distributionManagement> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pom.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package env; | ||
|
||
import java.util.Collections; | ||
import org.openqa.selenium.*; | ||
import org.openqa.selenium.chrome.*; | ||
import org.openqa.selenium.phantomjs.PhantomJSDriver; | ||
import org.openqa.selenium.remote.DesiredCapabilities; | ||
import org.openqa.selenium.support.ui.*; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import org.openqa.selenium.firefox.FirefoxDriver; | ||
import org.openqa.selenium.firefox.FirefoxOptions; | ||
import org.openqa.selenium.remote.ErrorHandler; | ||
|
||
/** | ||
* Created by tom on 24/02/17. | ||
*/ | ||
public class DriverUtil { | ||
public static long DEFAULT_WAIT = 20; | ||
private static int DEFAULT_WINDOW_WIDTH = 1920; | ||
private static int DEFAULT_WINDOW_HEIGHT = 1080; | ||
protected static WebDriver driver; | ||
|
||
public static WebDriver getDefaultDriver() { | ||
if (driver != null) { | ||
return driver; | ||
} | ||
System.setProperty("webdriver.chrome.driver", "./chromedriver"); | ||
System.setProperty("webdriver.gecko.driver", "./geckodriver"); | ||
DesiredCapabilities capabilities = null; //DesiredCapabilities.phantomjs(); | ||
capabilities = DesiredCapabilities.firefox(); | ||
capabilities.setJavascriptEnabled(true); | ||
capabilities.setCapability("takesScreenshot", true); | ||
driver = chooseDriver(capabilities); | ||
driver.manage().timeouts().setScriptTimeout(DEFAULT_WAIT, | ||
TimeUnit.SECONDS); | ||
driver.manage().window().setSize(new Dimension(DEFAULT_WINDOW_WIDTH, | ||
DEFAULT_WINDOW_HEIGHT)); | ||
return driver; | ||
} | ||
|
||
/** | ||
* By default to web driver will be PhantomJS | ||
* | ||
* Override it by passing -DWebDriver=Chrome to the command line arguments | ||
* @param capabilities | ||
* @return | ||
*/ | ||
private static WebDriver chooseDriver(DesiredCapabilities capabilities) { | ||
String preferredDriver = System.getProperty("WebDriver", "Firefox"); | ||
boolean headless = System.getProperty("Headless", "true").equals("true"); | ||
|
||
switch (preferredDriver) { | ||
case "Chrome": | ||
/* | ||
ChromeOptions options = new ChromeOptions(); | ||
options.addArguments("--headless", "--disable-gpu", "--disable-extensions", "--remote-debugging-port=9222"); | ||
//options.addArguments("--disable-gpu", "--disable-extensions"); | ||
//options.setBinary("/usr/bin/chromium-browser"); | ||
options.setBinary("/usr/bin/google-chrome"); | ||
capabilities.setCapability(ChromeOptions.CAPABILITY, options); | ||
ChromeDriver driver = new ChromeDriver(capabilities); | ||
*/ | ||
|
||
|
||
// /usr/bin/google-chrome | ||
final ChromeOptions chromeOptions = new ChromeOptions(); | ||
chromeOptions.setBinary("/usr/bin/chromium-browser"); | ||
if (headless) { | ||
chromeOptions.addArguments("--headless"); | ||
} | ||
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions); | ||
ChromeDriver driver = new ChromeDriver(capabilities); | ||
ErrorHandler handler = new ErrorHandler(); | ||
handler.setIncludeServerErrors(false); | ||
driver.setErrorHandler(handler); | ||
return driver; | ||
case "PhantomJS": | ||
return new PhantomJSDriver(capabilities); | ||
default: | ||
//return new PhantomJSDriver(capabilities); | ||
FirefoxOptions options = new FirefoxOptions(); | ||
//capabilities.s | ||
if (headless) { | ||
options.addArguments("-headless", "-safe-mode"); | ||
} | ||
capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options); | ||
final FirefoxDriver firefox = new FirefoxDriver(capabilities); | ||
return firefox; | ||
} | ||
} | ||
|
||
public static WebElement waitAndGetElementByCssSelector(WebDriver driver, String selector, | ||
int seconds) { | ||
By selection = By.cssSelector(selector); | ||
return (new WebDriverWait(driver, seconds)).until( // ensure element is visible! | ||
ExpectedConditions.visibilityOfElementLocated(selection)); | ||
} | ||
|
||
public static void closeDriver() { | ||
if (driver != null) { | ||
try { | ||
driver.close(); | ||
driver.quit(); // fails in current geckodriver! TODO: Fixme | ||
} catch (NoSuchMethodError nsme) { // in case quit fails | ||
} catch (NoSuchSessionException nsse) { // in case close fails | ||
} catch (SessionNotCreatedException snce) {} // in case close fails | ||
driver = null; | ||
} | ||
} | ||
} |
Oops, something went wrong.