Skip to content

Commit 62b8d78

Browse files
committed
merge sdk branch in master
1 parent 4c0c810 commit 62b8d78

24 files changed

+254
-629
lines changed

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ local.log
66
.gradle
77
build/
88
.DS_Store
9-
browserstack.err
10-
gradle/
9+
gradle
1110
gradlew
1211
gradlew.bat
13-
logs/
12+
logs

README.md

Lines changed: 77 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,96 @@
22

33
[TestNG](http://testng.org) Integration with BrowserStack.
44

5-
Master branch contains **Selenium 3** samples, for **Selenium 4 - W3C protocol** please checkout [selenium-4](https://github.com/browserstack/testng-browserstack/tree/selenium-4) branch
6-
75
![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780)
86

97
## Using Maven
108

11-
### Setup
12-
13-
* Clone the repo
9+
### Run sample build
10+
11+
- Clone the repository
12+
- Replace YOUR_USERNAME and YOUR_ACCESS_KEY with your BrowserStack access credentials in browserstack.yml.
13+
- Install dependencies `mvn compile`
14+
- To run the test suite having cross-platform with parallelization, run `mvn test -P sample-test`
15+
- To run local tests, run `mvn test -P sample-local-test`
16+
17+
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
18+
19+
### Integrate your test suite
20+
21+
This repository uses the BrowserStack SDK to run tests on BrowserStack. Follow the steps below to install the SDK in your test suite and run tests on BrowserStack:
22+
23+
* 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.
24+
* Add maven dependency of browserstack-java-sdk in your pom.xml file
25+
```sh
26+
<dependency>
27+
<groupId>com.browserstack</groupId>
28+
<artifactId>browserstack-java-sdk</artifactId>
29+
<version>LATEST</version>
30+
<scope>compile</scope>
31+
</dependency>
32+
```
33+
* 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`.
34+
```
35+
<plugin>
36+
<artifactId>maven-dependency-plugin</artifactId>
37+
<executions>
38+
<execution>
39+
<id>getClasspathFilenames</id>
40+
<goals>
41+
<goal>properties</goal>
42+
</goals>
43+
</execution>
44+
</executions>
45+
</plugin>
46+
<plugin>
47+
<groupId>org.apache.maven.plugins</groupId>
48+
<artifactId>maven-surefire-plugin</artifactId>
49+
<version>3.0.0-M5</version>
50+
<configuration>
51+
<suiteXmlFiles>
52+
<suiteXmlFile>config/sample-local-test.testng.xml</suiteXmlFile>
53+
</suiteXmlFiles>
54+
<argLine>
55+
-javaagent:${com.browserstack:browserstack-java-sdk:jar}
56+
</argLine>
57+
</configuration>
58+
</plugin>
59+
```
1460
* Install dependencies `mvn compile`
15-
* Update `*.conf.json` files inside the `src/test/resources/conf` directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings)
1661

17-
### Running your tests
62+
## Using Gradle
1863

19-
- To run a single test, run `mvn test -P single`
20-
- To run local tests, run `mvn test -P local`
21-
- To run parallel tests, run `mvn test -P parallel`
22-
- To run the test suite, run `mvn test -P suite`
64+
### Run sample build
2365

24-
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
25-
26-
27-
## Using Gradle
28-
29-
### Setup
66+
- Clone the repository
67+
- Install dependencies `gradle build`
68+
- To run the test suite having cross-platform with parallelization, run `gradle sampleTest`
69+
- To run local tests, run `gradle sampleLocalTest`
3070

31-
* Clone the repo
32-
* Install dependencies `gradle build`
33-
* Update `*.conf.json` files inside the `src/test/resources/conf` directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings)
71+
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
3472

35-
### Running your tests
73+
### Integrate your test suite
3674

37-
- To run a single test, run `gradle singleTest`
38-
- To run local tests, run `gradle localTest`
39-
- To run parallel tests, run `gradle parallelTest`
40-
- To run the test suite, run `gradle suiteTest`
75+
This repository uses the BrowserStack SDK to run tests on BrowserStack. Follow the steps below to install the SDK in your test suite and run tests on BrowserStack:
4176

42-
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
77+
* Following are the changes required in `gradle.build` -
78+
* Add `compileOnly 'com.browserstack:browserstack-java-sdk:latest.release'` in dependencies
79+
* Fetch Artifact Information and add `jvmArgs` property in tasks *SampleTest* and *SampleLocalTest* :
80+
```
81+
def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' }
82+
83+
task sampleTest(type: Test) {
84+
useTestNG() {
85+
dependsOn cleanTest
86+
useDefaultListeners = true
87+
suites "config/sample-test.testng.xml"
88+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
89+
}
90+
}
91+
```
92+
93+
* Install dependencies `gradle build`
4394

4495

4596
## Notes
4697
* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate)
47-
* To test on a different set of browsers, check out our [platform configurator](https://www.browserstack.com/automate/java#setting-os-and-browser)
48-
* You can export the environment variables for the Username and Access Key of your BrowserStack account
49-
50-
```
51-
export BROWSERSTACK_USERNAME=<browserstack-username> &&
52-
export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
53-
```
54-
55-
## Additional Resources
56-
* [Documentation for writing Automate test scripts in Java](https://www.browserstack.com/automate/java)
57-
* [Customizing your tests on BrowserStack](https://www.browserstack.com/automate/capabilities)
58-
* [Browsers & mobile devices for selenium testing on BrowserStack](https://www.browserstack.com/list-of-browsers-and-platforms?product=automate)
59-
* [Using REST API to access information about your tests via the command-line interface](https://www.browserstack.com/automate/rest-api)

browserstack.yml

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

build.gradle

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,37 @@ repositories { mavenCentral() }
77
dependencies {
88
implementation 'org.testng:testng:7.4.0'
99
implementation 'commons-io:commons-io:1.3.2'
10-
implementation 'org.seleniumhq.selenium:selenium-java:4.1.0'
10+
implementation 'org.seleniumhq.selenium:selenium-java:4.1.4'
1111
implementation 'com.browserstack:browserstack-local-java:1.0.6'
1212
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
13+
compileOnly 'com.browserstack:browserstack-java-sdk:latest.release'
1314
}
1415

1516
group = 'com.browserstack'
1617
version = '1.0-SNAPSHOT'
1718
description = 'testng-browserstack'
1819
sourceCompatibility = '1.8'
1920

21+
def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' }
22+
2023
tasks.withType(JavaCompile) {
2124
options.encoding = 'UTF-8'
2225
}
2326

24-
task singleTest(type: Test) {
25-
useTestNG() {
26-
dependsOn cleanTest
27-
useDefaultListeners = true
28-
suites "config/single.testng.xml"
29-
}
30-
}
31-
32-
task localTest(type: Test) {
33-
useTestNG() {
34-
dependsOn cleanTest
35-
useDefaultListeners = true
36-
suites "config/local.testng.xml"
37-
}
38-
}
39-
40-
task parallelTest(type: Test) {
27+
task sampleTest(type: Test) {
4128
useTestNG() {
42-
dependsOn cleanTest
43-
useDefaultListeners = true
44-
suites "config/parallel.testng.xml"
29+
dependsOn cleanTest
30+
useDefaultListeners = true
31+
suites "config/sample-test.testng.xml"
32+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
4533
}
4634
}
4735

48-
task suiteTest(type: Test) {
36+
task sampleLocalTest(type: Test) {
4937
useTestNG() {
50-
dependsOn cleanTest
51-
useDefaultListeners = true
52-
suites "config/suite.testng.xml"
38+
dependsOn cleanTest
39+
useDefaultListeners = true
40+
suites "config/sample-local-test.testng.xml"
41+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
5342
}
5443
}

config/parallel.testng.xml

Lines changed: 0 additions & 27 deletions
This file was deleted.

config/local.testng.xml renamed to config/sample-local-test.testng.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
33
<suite name="Local">
44
<test name="LocalTest">
5-
<parameter name="config" value="local.conf.json"/>
6-
<parameter name="environment" value="chrome"/>
75
<classes>
86
<class name="com.browserstack.LocalTest"/>
97
</classes>
108
</test>
119
</suite>
10+

config/sample-test.testng.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
3+
<suite name="Cross-Platform">
4+
<test name="BStackDemo">
5+
<classes>
6+
<class name="com.browserstack.BStackDemoTest" />
7+
</classes>
8+
</test>
9+
</suite>

config/single.testng.xml

Lines changed: 0 additions & 11 deletions
This file was deleted.

config/suite.testng.xml

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)