Skip to content

Commit b372ea0

Browse files
Merge pull request #16 from kamal-kaur04/add-test-samples-cucumber-testng
added test sample for cucumber-testng
2 parents d89ed8d + 06b99c4 commit b372ea0

File tree

15 files changed

+228
-452
lines changed

15 files changed

+228
-452
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
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

README.md

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,57 @@
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 a single test, run `mvn test -P single`
14-
* To run parallel tests, run `mvn test -P parallel`
15-
* To run local tests, run `mvn test -P local`
8+
### Run sample build
169

10+
- Clone the repository
11+
- Install dependencies `mvn compile`
12+
- To run the test suite having cross-platform with parallelization, run `mvn test -P sample-test`
13+
- To run local tests, run `mvn test -P sample-local-test`
1714

15+
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
16+
17+
### Integrate your test suite
18+
19+
* Install dependencies `mvn compile`
20+
* 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.
21+
* Add maven dependency of browserstack-java-sdk in your pom.xml file
22+
```sh
23+
<dependency>
24+
<groupId>com.browserstack</groupId>
25+
<artifactId>browserstack-java-sdk</artifactId>
26+
<version>LATEST</version>
27+
<scope>compile</scope>
28+
</dependency>
29+
```
30+
* 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`.
31+
```
32+
<plugin>
33+
<artifactId>maven-dependency-plugin</artifactId>
34+
<executions>
35+
<execution>
36+
<id>getClasspathFilenames</id>
37+
<goals>
38+
<goal>properties</goal>
39+
</goals>
40+
</execution>
41+
</executions>
42+
</plugin>
43+
<plugin>
44+
<groupId>org.apache.maven.plugins</groupId>
45+
<artifactId>maven-surefire-plugin</artifactId>
46+
<version>3.0.0-M5</version>
47+
<configuration>
48+
<suiteXmlFiles>
49+
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
50+
</suiteXmlFiles>
51+
<argLine>
52+
-javaagent:${com.browserstack:browserstack-java-sdk:jar}
53+
</argLine>
54+
</configuration>
55+
</plugin>
56+
```
1857

1958
## Notes
2059
* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate)

browserstack.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# =============================
2+
# Set BrowserStack Credentials
3+
# =============================
4+
# Add your BrowserStack userName and acccessKey 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+
# Organizing your tests
11+
# ======================
12+
# Use `projectName`, `buildName`, `name` capabilities to organise your tests
13+
# `name` is the name of your test sessions and is automatically picked from your
14+
# test name and doesn't need to be set manually when using BrowserStack SDK
15+
# `buildName` is used to name your CI/CD job or the execution of your test suite.
16+
# Ensure you add a dynamic identifier, like an incremental build number from your
17+
# CI/CD or timestamp at the end of every build; otherwise tests from different
18+
# executions will be grouped together on BrowserStack
19+
buildName: browserstack-build-1
20+
# Use `projectName` to set the name of your project. Example, Marketing Website
21+
projectName: BrowserStack Samples
22+
23+
# Use `framework` to set the framework of your project. Example, testng, cucumber, cucumber-testng
24+
framework: cucumber-testng
25+
26+
# =======================================
27+
# Platforms (Browsers / Devices to test)
28+
# =======================================
29+
# Platforms object contains all the browser / device combinations you want to test on.
30+
# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate)
31+
platforms:
32+
- os: OS X
33+
osVersion: Big Sur
34+
browser: Chrome
35+
browserVersion: latest
36+
- os: Windows
37+
osVersion: 10
38+
browser: Edge
39+
browserVersion: latest
40+
- device: Samsung Galaxy S22 Ultra
41+
browserName: chrome # Try 'samsung' for Samsung browser
42+
osVersion: 12.0
43+
44+
# =======================
45+
# Parallels per Platform
46+
# =======================
47+
# The number of parallel threads to be used for each platform set.
48+
# BrowserStack's SDK runner will select the best strategy based on the configured value
49+
#
50+
# 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
51+
#
52+
# 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
53+
parallelsPerPlatform: 1
54+
55+
# ==========================================
56+
# BrowserStack Local
57+
# (For localhost, staging/private websites)
58+
# ==========================================
59+
# Set browserStackLocal to true if your website under test is not accessible publicly over the internet
60+
# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction
61+
browserstackLocal: false # <boolean> (Default false)
62+
# browserStackLocalOptions:
63+
# Options to be passed to BrowserStack local in-case of advanced configurations
64+
# - localIdentifier: # <string> (Default: null) Needed if you need to run multiple instances of local.
65+
# - forceLocal: true # <boolean> (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel.
66+
# Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections
67+
68+
# ===================
69+
# Debugging features
70+
# ===================
71+
debug: false # <boolean> # Set to true if you need screenshots for every selenium command ran
72+
networkLogs: false # <boolean> Set to true to enable HAR logs capturing
73+
consoleLogs: errors # <string> Remote browser's console debug levels to be printed (Default: errors)
74+
# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors)

build.gradle

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

pom.xml

Lines changed: 29 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,15 @@
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1515
<maven.compiler.source>1.8</maven.compiler.source>
1616
<maven.compiler.target>1.8</maven.compiler.target>
17-
<cucumber.version>6.9.1</cucumber.version>
17+
<cucumber.version>7.4.1</cucumber.version>
1818
<testng.version>7.4.0</testng.version>
1919
<selenium-java.version>3.141.59</selenium-java.version>
2020
<browserstack-local-java.version>1.0.6</browserstack-local-java.version>
2121
<json-simple.version>1.1.1</json-simple.version>
22-
<slf4j.version>1.7.30</slf4j.version>
22+
<browserstack-java-sdk.version>LATEST</browserstack-java-sdk.version>
2323
</properties>
2424

2525
<dependencies>
26-
27-
<dependency>
28-
<groupId>org.slf4j</groupId>
29-
<artifactId>slf4j-api</artifactId>
30-
<version>${slf4j.version}</version>
31-
</dependency>
32-
<dependency>
33-
<groupId>org.slf4j</groupId>
34-
<artifactId>slf4j-simple</artifactId>
35-
<version>${slf4j.version}</version>
36-
</dependency>
37-
3826
<dependency>
3927
<groupId>org.testng</groupId>
4028
<artifactId>testng</artifactId>
@@ -64,7 +52,12 @@
6452
<artifactId>browserstack-local-java</artifactId>
6553
<version>${browserstack-local-java.version}</version>
6654
</dependency>
67-
55+
<dependency>
56+
<groupId>com.browserstack</groupId>
57+
<artifactId>browserstack-java-sdk</artifactId>
58+
<version>${browserstack-java-sdk.version}</version>
59+
<scope>compile</scope>
60+
</dependency>
6861
<dependency>
6962
<groupId>com.googlecode.json-simple</groupId>
7063
<artifactId>json-simple</artifactId>
@@ -75,7 +68,12 @@
7568
<artifactId>commons-lang3</artifactId>
7669
<version>3.11</version>
7770
</dependency>
78-
71+
<dependency>
72+
<groupId>io.qameta.allure</groupId>
73+
<artifactId>allure-testng</artifactId>
74+
<version>2.18.1</version>
75+
<scope>test</scope>
76+
</dependency>
7977
</dependencies>
8078

8179
<build>
@@ -89,11 +87,22 @@
8987
<target>8</target>
9088
</configuration>
9189
</plugin>
90+
<plugin>
91+
<artifactId>maven-dependency-plugin</artifactId>
92+
<executions>
93+
<execution>
94+
<id>getClasspathFilenames</id>
95+
<goals>
96+
<goal>properties</goal>
97+
</goals>
98+
</execution>
99+
</executions>
100+
</plugin>
92101
</plugins>
93102
</build>
94103
<profiles>
95104
<profile>
96-
<id>single</id>
105+
<id>sample-test</id>
97106
<activation>
98107
<activeByDefault>true</activeByDefault>
99108
</activation>
@@ -108,51 +117,19 @@
108117
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
109118
</suiteXmlFiles>
110119
<argLine>
111-
-Ddataproviderthreadcount=1
112-
</argLine>
113-
<systemPropertyVariables>
114-
<caps>src/test/resources/conf/single.conf.json</caps>
115-
<cucumber.publish.quiet>true</cucumber.publish.quiet>
116-
<cucumber.features>src/test/resources/features/test</cucumber.features>
117-
</systemPropertyVariables>
118-
</configuration>
119-
</plugin>
120-
</plugins>
121-
</build>
122-
</profile>
123-
<profile>
124-
<id>parallel</id>
125-
<build>
126-
<plugins>
127-
<plugin>
128-
<groupId>org.apache.maven.plugins</groupId>
129-
<artifactId>maven-surefire-plugin</artifactId>
130-
<version>3.0.0-M5</version>
131-
<configuration>
132-
<suiteXmlFiles>
133-
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
134-
</suiteXmlFiles>
135-
<argLine>
136-
-Ddataproviderthreadcount=4
120+
-javaagent:${com.browserstack:browserstack-java-sdk:jar}
137121
</argLine>
138122
<systemPropertyVariables>
139-
<caps>src/test/resources/conf/parallel.conf.json</caps>
140123
<cucumber.publish.quiet>true</cucumber.publish.quiet>
141124
<cucumber.features>src/test/resources/features/test</cucumber.features>
142125
</systemPropertyVariables>
143-
<properties>
144-
<property>
145-
<name>parallel</name>
146-
<value>methods</value>
147-
</property>
148-
</properties>
149126
</configuration>
150127
</plugin>
151128
</plugins>
152129
</build>
153130
</profile>
154131
<profile>
155-
<id>local</id>
132+
<id>sample-local-test</id>
156133
<build>
157134
<plugins>
158135
<plugin>
@@ -164,10 +141,9 @@
164141
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
165142
</suiteXmlFiles>
166143
<argLine>
167-
-Ddataproviderthreadcount=1
144+
-javaagent:${com.browserstack:browserstack-java-sdk:jar}
168145
</argLine>
169146
<systemPropertyVariables>
170-
<caps>src/test/resources/conf/local.conf.json</caps>
171147
<cucumber.publish.quiet>true</cucumber.publish.quiet>
172148
<cucumber.features>src/test/resources/features/localtest</cucumber.features>
173149
</systemPropertyVariables>

0 commit comments

Comments
 (0)