Skip to content

Commit

Permalink
Merge pull request #10 from geekdenz/master
Browse files Browse the repository at this point in the history
Fix issue #9: Succeed build.
  • Loading branch information
sameer49 authored Sep 22, 2017
2 parents 16ec003 + 65818f4 commit 8a2aa4b
Show file tree
Hide file tree
Showing 32 changed files with 591 additions and 749 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/target
settings.xml
chromedriver
geckodriver
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,34 @@ By using selenium-cucumber API's you can write code for your custom steps more e

The selenium-cucumber API's steps are located [here](doc/selenium-cucumber-java-API.md)

Using canned tests in your project
----------------------------------

In your TestRunner class add a glue option:

```
package stepDefintions;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(
plugin = {"html:target/cucumberHtmlReport"},
features = "classpath:features",
glue = {"info.seleniumcucumber.stepdefinitions"}
)
public class RunCukeTest {
}
```

Maven/Gradle Dependency
-----------------------

See https://jitpack.io/#geekdenz/selenium-cucumber-java .

License
-------
Expand Down
4 changes: 4 additions & 0 deletions downloadDriver.bash
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
182 changes: 105 additions & 77 deletions pom.xml
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>
1 change: 1 addition & 0 deletions selenium-cucumber-java-0.0.1.pom
4 changes: 0 additions & 4 deletions src/main/java/env/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@

public interface BaseTest
{
public static WebDriver driver = Env.CreateWebDriver(Env.getBrowserName());
public static WebDriverWait wait = new WebDriverWait(driver, 30);


MiscMethods miscmethodObj = new MiscMethods();
NavigateMethods navigationObj = new NavigateMethods();
AssertionMethods assertionObj = new AssertionMethods();
Expand Down
111 changes: 111 additions & 0 deletions src/main/java/env/DriverUtil.java
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;
}
}
}
Loading

0 comments on commit 8a2aa4b

Please sign in to comment.