Skip to content

Commit d55c4d9

Browse files
committed
Init commit
0 parents  commit d55c4d9

File tree

13 files changed

+338
-0
lines changed

13 files changed

+338
-0
lines changed

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Java template
3+
*.class
4+
5+
# Mobile Tools for Java (J2ME)
6+
.mtj.tmp/
7+
8+
# Package Files #
9+
*.jar
10+
*.war
11+
*.ear
12+
13+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
14+
hs_err_pid*
15+
16+
/.idea/
17+
*.iml

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
run_all_in_parallel:
2+
make clean_it test_parallel
3+
4+
clean_it:
5+
mvn clean
6+
7+
test_parallel:
8+
make -j test_firefox test_ie test_safari test_chrome
9+
10+
test_firefox:
11+
mvn install -Dbrowser=firefox
12+
13+
test_ie:
14+
mvn install -Dbrowser=IE
15+
16+
test_safari:
17+
mvn install -Dbrowser=safari
18+
19+
test_chrome:
20+
mvn install -Dbrowser=chrome

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Cucumber JVM-Browserstack
2+
[Cucumber JVM](https://cucumber.io/docs/reference/jvm) Integration with BrowserStack.
3+
4+
![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780)
5+
<img src="https://cucumber.io/images/cucumber-logo.svg" height="110" />
6+
7+
## Setup
8+
* Clone the repo
9+
* Install dependencies `mvn install`
10+
* Set environment variables with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings).
11+
12+
## Running your tests
13+
* To run a single test, run `mvn install -Dbrowser=<BROWSER>`
14+
* Note - use command line properties to set additional webdriver capabilities
15+
* To run parallel tests, run `make run_all_in_parallel`
16+
17+
18+
## Notes
19+
* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate)
20+
* To test on a different set of browsers, check out our [platform configurator](https://www.browserstack.com/automate/java#setting-os-and-browser)
21+
* You can export the environment variables for the Username and Access Key of your BrowserStack account.
22+
23+
```
24+
export BROWSERSTACK_USERNAME=<browserstack-username> &&
25+
export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
26+
```
27+
28+
## Addtional Resources
29+
* [Documentation for writing Automate test scripts in Java](https://www.browserstack.com/automate/java)
30+
* [Customizing your tests on BrowserStack](https://www.browserstack.com/automate/capabilities)
31+
* [Browsers & mobile devices for selenium testing on BrowserStack](https://www.browserstack.com/list-of-browsers-and-platforms?product=automate)
32+
* [Using REST API to access information about your tests via the command-line interface](https://www.browserstack.com/automate/rest-api)

pom.xml

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.browserstack</groupId>
6+
<artifactId>cucumber-jvm-java-browserstack</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>cucumber-jvm-java-browserstack</name>
11+
<url>http://maven.apache.org</url>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<cucumber.jvm.parallel.version>2.2.0</cucumber.jvm.parallel.version>
16+
<surefire.maven.plugin.version>2.19.1</surefire.maven.plugin.version>
17+
<acceptance.test.parallel.count>10</acceptance.test.parallel.count>
18+
</properties>
19+
20+
<dependencies>
21+
22+
<dependency>
23+
<groupId>info.cukes</groupId>
24+
<artifactId>cucumber-java</artifactId>
25+
<version>1.2.5</version>
26+
</dependency>
27+
28+
<dependency>
29+
<groupId>info.cukes</groupId>
30+
<artifactId>cucumber-junit</artifactId>
31+
<version>1.2.5</version>
32+
</dependency>
33+
34+
<dependency>
35+
<groupId>org.seleniumhq.selenium</groupId>
36+
<artifactId>selenium-java</artifactId>
37+
<version>3.0.1</version>
38+
<scope>test</scope>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>junit</groupId>
43+
<artifactId>junit</artifactId>
44+
<version>4.12</version>
45+
<scope>test</scope>
46+
</dependency>
47+
48+
<dependency>
49+
<groupId>org.apache.commons</groupId>
50+
<artifactId>commons-io</artifactId>
51+
<version>1.3.2</version>
52+
</dependency>
53+
54+
<dependency>
55+
<groupId>com.browserstack</groupId>
56+
<artifactId>browserstack-local-java</artifactId>
57+
<version>1.0.0</version>
58+
</dependency>
59+
60+
</dependencies>
61+
62+
<build>
63+
<plugins>
64+
<plugin>
65+
<artifactId>maven-compiler-plugin</artifactId>
66+
<version>3.3</version>
67+
<configuration>
68+
<source>1.6</source>
69+
<target>1.6</target>
70+
</configuration>
71+
</plugin>
72+
<plugin>
73+
<groupId>org.apache.maven.plugins</groupId>
74+
<artifactId>maven-surefire-plugin</artifactId>
75+
<version>${surefire.maven.plugin.version}</version>
76+
<executions>
77+
<execution>
78+
<id>acceptance-test</id>
79+
<phase>integration-test</phase>
80+
<goals>
81+
<goal>test</goal>
82+
</goals>
83+
<configuration>
84+
<forkCount>${acceptance.test.parallel.count}</forkCount>
85+
<reuseForks>true</reuseForks>
86+
<includes>
87+
<include>**/*IT.class</include>
88+
</includes>
89+
</configuration>
90+
</execution>
91+
</executions>
92+
</plugin>
93+
<plugin>
94+
<artifactId>maven-resources-plugin</artifactId>
95+
<version>3.0.2</version>
96+
<executions>
97+
<execution>
98+
<id>copy-resources</id>
99+
<!-- here the phase you need -->
100+
<phase>validate</phase>
101+
<goals>
102+
<goal>copy-resources</goal>
103+
</goals>
104+
<configuration>
105+
<outputDirectory>target/test-classes/com/yourcompany/cucumberjvm</outputDirectory>
106+
<resources>
107+
<resource>
108+
<directory>src/test/resources</directory>
109+
<filtering>true</filtering>
110+
</resource>
111+
</resources>
112+
</configuration>
113+
</execution>
114+
</executions>
115+
</plugin>
116+
<plugin>
117+
<groupId>com.github.temyers</groupId>
118+
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
119+
<version>${cucumber.jvm.parallel.version}</version>
120+
<executions>
121+
<execution>
122+
<id>generateRunners</id>
123+
<phase>validate</phase>
124+
<goals>
125+
<goal>generateRunners</goal>
126+
</goals>
127+
<configuration>
128+
<!-- Mandatory -->
129+
<!-- comma separated list of package names to scan for glue code -->
130+
<glue>com.browserstack.stepdefs</glue>
131+
<!-- These are the default values -->
132+
<!-- Where to output the generated Junit tests -->
133+
<outputDirectory>${project.build.directory}/generated-test-sources/features</outputDirectory>
134+
<!-- The diectory containing your feature files. -->
135+
<featuresDirectory>src/test/java/resources/features</featuresDirectory>
136+
<cucumberOutputDir>${project.build.directory}/cucumber_reports/test_results</cucumberOutputDir>
137+
<!-- comma separated list of output formats -->
138+
<format>junit</format>
139+
<!-- CucumberOptions.strict property -->
140+
<strict>true</strict>
141+
<!-- CucumberOptions.monochrome property -->
142+
<monochrome>true</monochrome>
143+
<!-- The tags to run, maps to CucumberOptions.tags property -->
144+
<tags>"~@ignore"</tags>
145+
146+
<namingScheme>pattern</namingScheme>
147+
<!-- The class naming pattern to use. Only required/used if naming scheme is 'pattern'.-->
148+
<namingPattern>{f}_Parallel{c}IT</namingPattern>
149+
150+
<!-- If set to true, only feature files containing the required tags shall be generated. -->
151+
<!-- Excluded tags (~@notMe) are ignored. -->
152+
<filterFeaturesByTags>true</filterFeaturesByTags>
153+
</configuration>
154+
</execution>
155+
</executions>
156+
</plugin>
157+
</plugins>
158+
</build>
159+
160+
</project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.browserstack.pageobjects;
2+
3+
import org.openqa.selenium.By;
4+
import org.openqa.selenium.WebDriver;
5+
6+
public class SearchPage {
7+
private static WebDriver webDriver;
8+
9+
public SearchPage(WebDriver webDriver) {
10+
this.webDriver = webDriver;
11+
}
12+
13+
private By searchTermField = By.name("q");
14+
private By submitSearch = By.id("_fZl");
15+
16+
public void enterSearchTerm(String searchTerm) {
17+
webDriver.findElement(searchTermField).sendKeys(searchTerm);
18+
}
19+
20+
public void submitSearch() {
21+
webDriver.findElement(submitSearch).click();
22+
}
23+
24+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.browserstack.stepdefs;
2+
3+
import com.browserstack.pageobjects.SearchPage;
4+
import cucumber.api.Scenario;
5+
import cucumber.api.java.After;
6+
import cucumber.api.java.Before;
7+
import cucumber.api.java.en.Given;
8+
import cucumber.api.java.en.Then;
9+
import cucumber.api.java.en.When;
10+
import org.openqa.selenium.WebDriver;
11+
import org.openqa.selenium.remote.DesiredCapabilities;
12+
import org.openqa.selenium.remote.RemoteWebDriver;
13+
14+
import java.net.URL;
15+
16+
import static org.junit.Assert.assertEquals;
17+
18+
public class SearchSteps {
19+
private WebDriver driver;
20+
private SearchPage searchPage;
21+
22+
@Before
23+
public void setUp(Scenario scenario) throws Exception {
24+
String USERNAME = System.getenv("BROWSERSTACK_USERNAME");
25+
String ACCESS_KEY = System.getenv("BROWSERSTACK_ACCESSKEY");
26+
String URL = "https://" + USERNAME + ":" + ACCESS_KEY + "@hub.browserstack.com/wd/hub";
27+
28+
DesiredCapabilities caps = new DesiredCapabilities();
29+
caps.setCapability("browser", System.getProperty("browser"));
30+
31+
driver = new RemoteWebDriver(new URL(URL), caps);
32+
searchPage = new SearchPage(driver);
33+
}
34+
35+
@Given("^I am on the website '(.+)'$")
36+
public void I_am_on_the_website(String url) throws Throwable {
37+
driver.get(url);
38+
}
39+
40+
@When("^I submit the search term '(.+)'$")
41+
public void I_submit_the_search_term(String searchTerm) throws Throwable {
42+
searchPage.enterSearchTerm(searchTerm);
43+
searchPage.submitSearch();
44+
}
45+
46+
@Then("the page title should be '(.+)'$")
47+
public void I_should_see_pagetitle(String expectedTitle) throws Throwable {
48+
assertEquals(expectedTitle, driver.getTitle());
49+
}
50+
51+
@After
52+
public void teardown() throws Exception {
53+
driver.quit();
54+
}
55+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Feature: Automatically correct mistyped search terms
2+
3+
Scenario: Enter search term and view related images
4+
Given I am on the website 'http://www.google.com'
5+
When I submit the search term 'BrowserStack'
6+
Then the page title should be 'BrowserStack - Google Search'

target/cucumber_reports/test_results/1.junit

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import org.junit.runner.RunWith;
2+
3+
import cucumber.api.CucumberOptions;
4+
import cucumber.api.junit.Cucumber;
5+
6+
@RunWith(Cucumber.class)
7+
@CucumberOptions(strict = true,
8+
features = {"/Users/charlielee/Desktop/demos/java/unfinished/cucumberjavabrowserstack/src/test/java/resources/features/Search.feature"},
9+
plugin = {"junit:/Users/charlielee/Desktop/demos/java/unfinished/cucumberjavabrowserstack/target/cucumber_reports/test_results/1.junit"},
10+
monochrome = true,
11+
tags = {"~@ignore"}, glue = { "com.browserstack.stepdefs" })
12+
public class Search_Parallel01IT {
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#Generated by Maven
2+
#Fri Jan 06 17:25:10 PST 2017
3+
version=0.0.1-SNAPSHOT
4+
groupId=com.yourcompany
5+
artifactId=cucumberjvmjavabrowserstack

0 commit comments

Comments
 (0)