Skip to content

Commit 4f7a819

Browse files
authored
Merge pull request #24 from kamal-kaur04/merge-sdk-branch-in-master
Merge sdk branch in master
2 parents 7609383 + 056a2ab commit 4f7a819

File tree

16 files changed

+295
-508
lines changed

16 files changed

+295
-508
lines changed

.gitignore

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@
1313
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
1414
hs_err_pid*
1515
target/
16+
logs/
1617
/.idea/
1718
*.iml
1819

1920
local.log
2021
reports
21-
.settings
2222
.gradle
23-
test-output
24-
logs
25-
build
2623
gradle
27-
.project
24+
build
25+
26+
# Eclipse generated
2827
.classpath
28+
.project
29+
.settings
30+
test-output

README.md

Lines changed: 87 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,99 @@
11
# Cucumber Java Browserstack
2-
<img src="src/test/resources/img/browserstack.png" width="60" height="60" ><img src="src/test/resources/img/cucumber.png" width="60" height="60" >
2+
![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780)
33

44
[Cucumber JVM](https://cucumber.io/docs/reference/jvm) Integration with BrowserStack.
55

6-
## Setup
7-
* Clone the repo
8-
* Install dependencies `mvn install`
9-
* Set environment variables with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings).
10-
* Update `*.conf.js` files inside the `src/test/resources/conf/` directory to update desired capabilities.
6+
## Using Maven
117

12-
## Running your tests
13-
* To run tests, run `mvn test -P parallel`
14-
* To run local tests, run `mvn test -P local`
8+
### Run sample build
159

10+
- Clone the repository
11+
- Replace YOUR_USERNAME and YOUR_ACCESS_KEY with your BrowserStack access credentials in browserstack.yml.
12+
- Install dependencies `mvn compile`
13+
- To run the test suite having cross-platform with parallelization, run `mvn test -P sample-test`
14+
- To run local tests, run `mvn test -P sample-local-test`
15+
- To view Allure Reports, run `allure serve target/allure-results`
1616

17+
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
1718

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.
19+
### Integrate your test suite
20+
21+
* Install dependencies `mvn compile`
22+
* Create sample browserstack.yml file with the browserstack related capabilities with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings) and place it in your root folder.
23+
* Add maven dependency of browserstack-java-sdk in your pom.xml file
24+
```sh
25+
<dependency>
26+
<groupId>com.browserstack</groupId>
27+
<artifactId>browserstack-java-sdk</artifactId>
28+
<version>LATEST</version>
29+
<scope>compile</scope>
30+
</dependency>
31+
```
32+
* Modify your build plugin to run tests by adding argLine `-javaagent:${com.browserstack:browserstack-java-sdk:jar}` and `maven-dependency-plugin` for resolving dependencies in the profiles `sample-test` and `sample-local-test`.
33+
```
34+
<plugin>
35+
<artifactId>maven-dependency-plugin</artifactId>
36+
<executions>
37+
<execution>
38+
<id>getClasspathFilenames</id>
39+
<goals>
40+
<goal>properties</goal>
41+
</goals>
42+
</execution>
43+
</executions>
44+
</plugin>
45+
<plugin>
46+
<groupId>org.apache.maven.plugins</groupId>
47+
<artifactId>maven-surefire-plugin</artifactId>
48+
<version>3.0.0-M5</version>
49+
<configuration>
50+
<suiteXmlFiles>
51+
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
52+
</suiteXmlFiles>
53+
<argLine>
54+
-javaagent:${com.browserstack:browserstack-java-sdk:jar}
55+
</argLine>
56+
</configuration>
57+
</plugin>
58+
```
59+
60+
### Migrate from Vanilla Cucumber to use Testng Runner
61+
* If you are using Vanilla Cucumber CLI, you can migrate to use TestNG Runner with BrowserStack using the below command :
62+
```
63+
mvn archetype:generate -DarchetypeGroupId=com.browserstack -DarchetypeArtifactId=cucumber-testng-archetype -DarchetypeVersion=1.0 -DgroupId=com.browserstack -DartifactId=cucumber-testng-archetype -Dversion=1.0 -DinteractiveMode=false
64+
```
65+
* Run your tests using `mvn test`
66+
* To use specific `@CucumberOptions` in generated class `BrowserStackCucumberTestNgRunner`, refer - https://javadoc.io/static/io.cucumber/cucumber-testng/5.0.0-RC2/io/cucumber/testng/CucumberOptions.html
67+
68+
## Using Gradle
69+
70+
### Run sample build
2271

72+
- Clone the repository
73+
- Install dependencies `gradle build`
74+
- To run the test suite having cross-platform with parallelization, run `gradle sampleTest`
75+
- To run local tests, run `gradle sampleLocalTest`
76+
77+
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
78+
79+
### Integrate your test suite
80+
81+
* Install dependencies `gradle build`
82+
* Following are the changes required in `gradle.build` -
83+
* Add `compileOnly 'com.browserstack:browserstack-java-sdk:latest.release'` in dependencies
84+
* Fetch Artifact Information and add `jvmArgs` property in tasks *SampleTest* and *SampleLocalTest* :
2385
```
24-
export BROWSERSTACK_USERNAME=<browserstack-username> &&
25-
export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
86+
def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' }
87+
88+
task sampleTest(type: Test) {
89+
useTestNG() {
90+
dependsOn cleanTest
91+
useDefaultListeners = true
92+
suites "config/sample-test.testng.xml"
93+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
94+
}
95+
}
2696
```
2797

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)
98+
## Notes
99+
* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate)

browserstack.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# =============================
2+
# Set BrowserStack Credentials
3+
# =============================
4+
# Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME and
5+
# BROWSERSTACK_ACCESS_KEY as env variables
6+
userName: YOUR_USERNAME
7+
accessKey: YOUR_ACCESS_KEY
8+
9+
# ======================
10+
# BrowserStack Reporting
11+
# ======================
12+
# The following capabilities are used to set up reporting on BrowserStack:
13+
# Set 'projectName' to the name of your project. Example, Marketing Website
14+
projectName: BrowserStack Samples
15+
# Set `buildName` as the name of the job / testsuite being run
16+
buildName: browserstack build
17+
# `buildIdentifier` is a unique id to differentiate every execution that gets appended to
18+
# buildName. Choose your buildIdentifier format from the available expressions:
19+
# ${BUILD_NUMBER} (Default): Generates an incremental counter with every execution
20+
# ${DATE_TIME}: Generates a Timestamp with every execution. Eg. 05-Nov-19:30
21+
# Read more about buildIdentifiers here -> https://www.browserstack.com/docs/automate/selenium/organize-tests
22+
buildIdentifier: '#${BUILD_NUMBER}' # Supports strings along with either/both ${expression}
23+
# Set `framework` of your test suite. Example, `testng`, `cucumber`, `cucumber-testng`
24+
# This property is needed to send test context to BrowserStack (test name, status)
25+
framework: cucumber-testng
26+
27+
# =======================================
28+
# Platforms (Browsers / Devices to test)
29+
# =======================================
30+
# Platforms object contains all the browser / device combinations you want to test on.
31+
# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate)
32+
platforms:
33+
- os: OS X
34+
osVersion: Big Sur
35+
browserName: Chrome
36+
browserVersion: latest
37+
- os: Windows
38+
osVersion: 10
39+
browserName: Edge
40+
browserVersion: latest
41+
- deviceName: Samsung Galaxy S22 Ultra
42+
browserName: chrome # Try 'samsung' for Samsung browser
43+
osVersion: 12.0
44+
45+
# =======================
46+
# Parallels per Platform
47+
# =======================
48+
# The number of parallel threads to be used for each platform set.
49+
# BrowserStack's SDK runner will select the best strategy based on the configured value
50+
#
51+
# Example 1 - If you have configured 3 platforms and set `parallelsPerPlatform` as 2, a total of 6 (2 * 3) parallel threads will be used on BrowserStack
52+
#
53+
# Example 2 - If you have configured 1 platform and set `parallelsPerPlatform` as 5, a total of 5 (1 * 5) parallel threads will be used on BrowserStack
54+
parallelsPerPlatform: 1
55+
56+
# ==========================================
57+
# BrowserStack Local
58+
# (For localhost, staging/private websites)
59+
# ==========================================
60+
# Set browserStackLocal to true if your website under test is not accessible publicly over the internet
61+
# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction
62+
browserstackLocal: true # <boolean> (Default false)
63+
64+
# Options to be passed to BrowserStack local in-case of advanced configurations
65+
# browserStackLocalOptions:
66+
# localIdentifier: # <string> (Default: null) Needed if you need to run multiple instances of local.
67+
# forceLocal: true # <boolean> (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel.
68+
# Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections
69+
70+
# ===================
71+
# Debugging features
72+
# ===================
73+
debug: false # <boolean> # Set to true if you need screenshots for every selenium command ran
74+
networkLogs: false # <boolean> Set to true to enable HAR logs capturing
75+
consoleLogs: errors # <string> Remote browser's console debug levels to be printed (Default: errors)
76+
# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors)

build.gradle

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
plugins {
2+
id 'java'
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
dependencies {
10+
implementation 'org.seleniumhq.selenium:selenium-java:4.1.4'
11+
testImplementation 'io.cucumber:cucumber-java:7.3.4'
12+
testImplementation 'io.cucumber:cucumber-testng:7.3.4'
13+
testImplementation 'io.cucumber:cucumber-core:7.3.4'
14+
compileOnly 'com.browserstack:browserstack-java-sdk:latest.release'
15+
}
16+
17+
group = 'com.browserstack'
18+
version = '1.0-SNAPSHOT'
19+
description = 'cucumber-java-browserstack'
20+
sourceCompatibility = '1.8'
21+
targetCompatibility = '1.8'
22+
23+
def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' }
24+
25+
tasks.withType(JavaCompile) {
26+
options.encoding = 'UTF-8'
27+
}
28+
29+
tasks.withType(Test) {
30+
systemProperties = System.properties
31+
}
32+
33+
task sampleTest(type: Test) {
34+
systemProperty "cucumber.publish.quiet", "true"
35+
systemProperty "cucumber.features", "src/test/resources/features/test"
36+
systemProperties System.getProperties()
37+
useTestNG() {
38+
dependsOn clean
39+
useDefaultListeners = true
40+
suites "src/test/resources/testng.xml"
41+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
42+
}
43+
scanForTestClasses = false
44+
}
45+
46+
task sampleLocalTest(type: Test) {
47+
systemProperty "cucumber.publish.quiet", "true"
48+
systemProperty "cucumber.features", "src/test/resources/features/localtest"
49+
systemProperties System.getProperties()
50+
useTestNG() {
51+
dependsOn clean
52+
useDefaultListeners = true
53+
suites "src/test/resources/testng.xml"
54+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
55+
}
56+
scanForTestClasses = false
57+
}

0 commit comments

Comments
 (0)