Skip to content

Commit 0f74c74

Browse files
SDK integration (#2) (#3)
Co-authored-by: Hrishikesh Bharati <hrishi1096> Thomas Schoemaecker <[email protected]> Co-authored-by: Hrishikesh Bharati <[email protected]>
1 parent ca55fb5 commit 0f74c74

26 files changed

+713
-417
lines changed

README.md

+97-32
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,6 @@ This repository contains the following Selenium tests:
5656
- [BrowserStack](#browserstack)
5757

5858

59-
## Configuring the maximum parallel test threads for this repository
60-
61-
For all the parallel run configuration profiles, you can configure the maximum parallel test threads by changing the settings below.
62-
63-
- BrowserStack
64-
65-
Maven:
66-
67-
`pom.xml`
68-
```xml
69-
<testng.parallel>classes</testng.parallel>
70-
<testng.threadCount>5</testng.threadCount>
71-
```
72-
73-
Gradle:
74-
75-
`gradle.properties`
76-
```sh
77-
testngParallel=classes
78-
testngThreadCount=5
79-
```
80-
8159
## Test Reporting
8260

8361
- [Allure reports](#generating-allure-reports)
@@ -102,12 +80,12 @@ This infrastructure points to running the tests on your own machine using simula
10280
To run the default test scenario (e.g. End to End Scenario) on your own machine, use the following command:
10381

10482
Maven:
105-
```sh
83+
```sh
10684
mvn clean test -P on-prem
10785
```
10886

10987
Gradle:
110-
```sh
88+
```sh
11189
gradle clean on-prem
11290
```
11391

@@ -176,11 +154,11 @@ This infrastructure points to running the tests on your own machine using simula
176154
set BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
177155
```
178156

179-
Alternatively, you can also hardcode username and access_key objects in the [test_caps.json](resources/conf/capabilities/test_caps.json) file.
157+
Alternatively, you can also hardcode username and access_key objects in the [browserstack.yml](resources/conf/capabilities/browserstack-single.yml) file.
180158

181159
Note:
182-
- We have configured a list of test capabilities in the [test_caps.json](resources/conf/capabilities/test_caps.json) file. You can certainly update them based on your device test requirements.
183-
- The exact test capability values can be easily identified using the [Browserstack Capability Generator](https://browserstack.com/app-automate/capabilities)
160+
- We have configured a list of test capabilities in the [browserstack.yml](resources/conf/capabilities/browserstack-single.yml) file. You can certainly update them based on your device / browser test requirements.
161+
- The exact test capability values can be easily identified using the [Browserstack Capability Generator](https://browserstack.com/automate/capabilities)
184162

185163

186164
## Running Your Tests on BrowserStack
@@ -201,12 +179,38 @@ curl -u "browserstack_username:browserstack_access_key" \
201179

202180
More information on [Upload apps from filesystem](https://www.browserstack.com/docs/app-automate/appium/upload-app-from-filesystem), [Upload apps using public URL](https://www.browserstack.com/docs/app-automate/appium/upload-app-using-public-url) or [Define custom ID for app](https://www.browserstack.com/docs/app-automate/appium/upload-app-define-custom-id).
203181

182+
**OR**
183+
184+
With Browserstack SDK, all the effort is taken away from the user.
185+
186+
All you need to do is add specify the path of your `APK` or `IPA` file in your browserstack.yml as shown below:
187+
```
188+
app: ./path/to/my/demo/app.apk
189+
```
190+
191+
If your app does indeed exist in the path provided, the sdk will be able to identify it, upload it, and use it for your tests.
192+
204193
### Run a specific test on BrowserStack
205194

206-
In this section, we will run a single test on an Android device on Browserstack. To change test capabilities for this configuration, please refer to the `single` object in `caps.json` file.
195+
In this section, we will run a single test on an Android device on Browserstack. To change test capabilities for this configuration, please refer to the `browserstack-single.yml` file in resources/conf/capabilities/
207196

208197
- How to run the test?
209198

199+
- Copy the capabilities to the root of the project:
200+
201+
- For \*nix based and Mac machines:
202+
203+
```sh
204+
rm -f -- browserstack.yml
205+
ln src/test/resources/conf/capabilities/browserstack-single.yml browserstack.yml
206+
```
207+
208+
- For Windows:
209+
210+
```sh
211+
del /f "browserstack.yml" && copy /y .\src\test\resources\conf\capabilities\browserstack-single.yml browserstack.yml
212+
```
213+
210214
- To run the default test scenario (e.g. End to End Scenario) on a BrowserStack device, use the following command:
211215

212216
Maven:
@@ -240,10 +244,25 @@ In this section, we will run a single test on an Android device on Browserstack.
240244

241245
### Run the entire test suite in parallel on a single BrowserStack device
242246

243-
In this section, we will run the tests in parallel on a single device on Browserstack. Refer to `single` object in `test_caps.json` file to change test capabilities for this configuration.
247+
In this section, we will run the tests in parallel on a single device on Browserstack. To change test capabilities for this configuration, please refer to the `browserstack-parallel.yml` file in resources/conf/capabilities/
244248

245249
- How to run the test?
246250

251+
- Copy the capabilities to the root of the project:
252+
253+
- For \*nix based and Mac machines:
254+
255+
```sh
256+
rm -f -- browserstack.yml
257+
ln src/test/resources/conf/capabilities/browserstack-parallel.yml browserstack.yml
258+
```
259+
260+
- For Windows:
261+
262+
```sh
263+
del /f "browserstack.yml" && copy /y .\src\test\resources\conf\capabilities\browserstack-parallel.yml browserstack.yml
264+
```
265+
247266
To run the entire test suite in parallel on a single BrowserStack device, use the following command:
248267

249268
Maven:
@@ -265,10 +284,26 @@ In this section, we will run the tests in parallel on a single device on Browser
265284

266285
### Run the entire test suite in parallel on multiple BrowserStack devices
267286

268-
In this section, we will run the tests in parallel on multiple devices on Browserstack. Refer to the `parallel` object in `caps.json` file to change test capabilities for this configuration.
287+
In this section, we will run the tests in parallel on multiple devices on Browserstack. To change test capabilities for this configuration, please refer to the `browserstack-parallel-devices.yml` file in resources/conf/capabilities/
269288

270289
- How to run the test?
271290

291+
- Copy the capabilities to the root of the project:
292+
293+
- For \*nix based and Mac machines:
294+
295+
```sh
296+
rm -f -- browserstack.yml
297+
ln src/test/resources/conf/capabilities/browserstack-parallel-devices.yml browserstack.yml
298+
```
299+
300+
- For Windows:
301+
302+
```sh
303+
del /f "browserstack.yml" && copy /y .\src\test\resources\conf\capabilities\browserstack-parallel-devices.yml browserstack.yml
304+
```
305+
306+
272307
To run the entire test suite in parallel on multiple BrowserStack devices, use the following command:
273308

274309
Maven:
@@ -293,7 +328,7 @@ In this section, we will run the tests in parallel on multiple devices on Browse
293328
- We will change the response of the `signin` (for the `locked_user`) API endpoint. (File to change: `pages/api/signin.js` line `43`)
294329
- The API endpoint respond with a specific error, `Your account has been locked.`.
295330
- We will change that to something generic, like: `Something went wrong.`
296-
- In this section, we will run a single test case that changes the API used in BrowserStack Demo app, in a wat that it interact with you local machine. Refer to the `single_local` object in `caps.json` file to change test capabilities for this configuration.
331+
- In this section, we will run a single test case that changes the API used in BrowserStack Demo app, in a wat that it interact with you local machine. Refer to the `browserstack-local.yml` file to change test capabilities for this configuration.
297332
- Note: You may need to provide additional BrowserStackLocal arguments to successfully connect your localhost environment with BrowserStack infrastructure. (e.g if you are behind firewalls, proxy or VPN).
298333
- Further details for successfully creating a BrowserStackLocal connection can be found here:
299334

@@ -305,6 +340,21 @@ In this section, we will run the tests in parallel on multiple devices on Browse
305340

306341
- How to run the test?
307342

343+
- Copy the capabilities to the root of the project:
344+
345+
- For \*nix based and Mac machines:
346+
347+
```sh
348+
rm -f -- browserstack.yml
349+
ln src/test/resources/conf/capabilities/browserstack-local.yml browserstack.yml
350+
```
351+
352+
- For Windows:
353+
354+
```sh
355+
del /f "browserstack.yml" && copy /y .\src\test\resources\conf\capabilities\browserstack-local.yml browserstack.yml
356+
```
357+
308358
- To run the default test scenario (e.g. End to End Scenario) on a single BrowserStack device using BrowserStackLocal, use the following command:
309359

310360
Maven:
@@ -324,10 +374,25 @@ In this section, we will run the tests in parallel on multiple devices on Browse
324374

325375
### [Mobile application using local or internal environment] Run the entire test suite in parallel on multiple BrowserStack devices using BrowserStackLocal
326376

327-
In this section, we will run the test cases on a mobile application using a local or internal environment in parallel on multiple devices on Browserstack. Refer to the `parallel_local` object in `caps.json` file to change test capabilities for this configuration.
377+
In this section, we will run the test cases on a mobile application using a local or internal environment in parallel on multiple devices on Browserstack. To change test capabilities for this configuration, please refer to the `browserstack-local-parallel-devices.yml` file in resources/conf/capabilities/
328378

329379
- How to run the test?
330380

381+
- Copy the capabilities to the root of the project:
382+
383+
- For \*nix based and Mac machines:
384+
385+
```sh
386+
rm -f -- browserstack.yml
387+
ln src/test/resources/conf/capabilities/browserstack-local-parallel-devices.yml browserstack.yml
388+
```
389+
390+
- For Windows:
391+
392+
```sh
393+
del /f "browserstack.yml" && copy /y .\src\test\resources\conf\capabilities\browserstack-local-parallel-devices.yml browserstack.yml
394+
```
395+
331396
To run the entire test suite in parallel on multiple BrowserStack devices using BrowserStackLocal, use the following command:
332397

333398
Maven:

apps/browserstack-demoapp.apk

60.3 MB
Binary file not shown.

build.gradle

+44-36
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,29 @@ buildscript {
1515
}
1616

1717
dependencies {
18-
implementation 'io.appium:java-client:7.0.0'
19-
implementation 'com.browserstack:browserstack-local-java:1.0.6'
20-
implementation 'org.testng:testng:7.1.0'
21-
implementation 'io.qameta.allure:allure-testng:2.13.8'
22-
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
23-
implementation 'org.assertj:assertj-core:3.18.0'
24-
implementation 'com.opencsv:opencsv:5.4'
25-
implementation 'org.slf4j:slf4j-api:1.7.30'
26-
implementation 'org.slf4j:slf4j-simple:1.7.30'
18+
testImplementation 'io.appium:java-client:7.0.0'
19+
compileOnly 'com.browserstack:browserstack-java-sdk:latest.release'
20+
testImplementation 'com.browserstack:browserstack-local-java:1.0.6'
21+
testImplementation 'org.testng:testng:7.1.0'
22+
testImplementation 'io.qameta.allure:allure-testng:2.13.8'
23+
testImplementation 'com.googlecode.json-simple:json-simple:1.1.1'
24+
testImplementation 'org.assertj:assertj-core:3.18.0'
25+
testImplementation 'com.opencsv:opencsv:5.4'
26+
testImplementation 'org.slf4j:slf4j-api:1.7.30'
27+
testImplementation 'org.slf4j:slf4j-simple:1.7.30'
28+
}
29+
30+
configurations {
31+
testCompile
2732
}
2833

2934
group = 'com.browserstack'
3035
version = '1.0-SNAPSHOT'
3136
description = 'browserstack-examples-testng'
3237
sourceCompatibility = JavaVersion.VERSION_1_8
3338

39+
def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' }
40+
3441
allure {
3542
autoconfigure = true
3643
version = '2.8.1'
@@ -44,84 +51,87 @@ tasks.register('on-prem', Test) {
4451
} else {
4552
include '**/OrderTest.class'
4653
}
54+
systemProperty "on-prem", "true"
4755
testLogging {
4856
events "PASSED", "FAILED", "SKIPPED"
4957
}
5058
}
5159

5260
tasks.register('on-prem-suite', Test) {
5361
useTestNG()
62+
systemProperty "on-prem", "true"
5463
testLogging {
5564
events "PASSED", "FAILED", "SKIPPED"
5665
}
5766
}
5867

5968
tasks.register('bstack-single', Test) {
6069
useTestNG() {
61-
listeners.add("com.browserstack.test.utils.BrowserstackTestStatusListener")
70+
dependsOn clean
71+
useDefaultListeners = true
72+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
6273
}
6374
if (project.hasProperty('test-name')) {
6475
include '**/' + project.property('test-name') + '.class'
6576
} else {
6677
include '**/OrderTest.class'
6778
}
68-
systemProperty "environment", "remote"
69-
systemProperty "testType", "single"
79+
systemProperty "browserstack-local", "false"
7080
testLogging {
7181
events "PASSED", "FAILED", "SKIPPED"
7282
}
7383
}
7484

7585
tasks.register('bstack-local', Test) {
7686
useTestNG() {
77-
listeners.add("com.browserstack.test.utils.BrowserstackTestStatusListener")
87+
dependsOn clean
88+
useDefaultListeners = true
89+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
7890
}
7991
if (project.hasProperty('test-name')) {
8092
include '**/' + project.property('test-name') + '.class'
8193
} else {
8294
include '**/OrderTest.class'
8395
}
84-
systemProperty "environment", "remote"
85-
systemProperty "testType", "local"
96+
systemProperty "browserstack-local", "true"
8697
testLogging {
8798
events "PASSED", "FAILED", "SKIPPED"
8899
}
89100
}
90101

91102
tasks.register('bstack-local-parallel', Test) {
92103
useTestNG() {
93-
parallel project.property('testngParallel')
94-
threadCount Integer.parseInt(project.property('testngThreadCount'))
95-
listeners.add("com.browserstack.test.utils.BrowserstackTestStatusListener")
104+
dependsOn clean
105+
useDefaultListeners = true
106+
suites 'src/test/resources/conf/runners/testng.xml'
107+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
96108
}
97-
systemProperty "environment", "remote"
98-
systemProperty "testType", "local"
109+
systemProperty "browserstack-local", "true"
99110
testLogging {
100111
events "PASSED", "FAILED", "SKIPPED"
101112
}
102113
}
103114

104115
tasks.register('bstack-local-parallel-devices', Test) {
105116
useTestNG() {
106-
suites 'src/test/resources/conf/runners/testng-browserstack-parallel.xml'
107-
parallel project.property('testngParallel')
108-
threadCount Integer.parseInt(project.property('testngThreadCount'))
109-
listeners.add("com.browserstack.test.utils.BrowserstackTestStatusListener")
117+
dependsOn clean
118+
useDefaultListeners = true
119+
suites 'src/test/resources/conf/runners/testng.xml'
120+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
110121
}
111-
systemProperty "environment", "remote"
112-
systemProperty "testType", "local"
113122
testLogging {
114123
events "PASSED", "FAILED", "SKIPPED"
115124
}
116125
}
117126

118127
tasks.register('bstack-parallel', Test) {
119128
useTestNG() {
120-
parallel project.property('testngParallel')
121-
threadCount Integer.parseInt(project.property('testngThreadCount'))
122-
listeners.add("com.browserstack.test.utils.BrowserstackTestStatusListener")
129+
dependsOn clean
130+
useDefaultListeners = true
131+
suites 'src/test/resources/conf/runners/testng.xml'
132+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
123133
}
124-
systemProperty "environment", "remote"
134+
systemProperty "browserstack-local", "false"
125135
systemProperty "testType", "parallel"
126136
testLogging {
127137
events "PASSED", "FAILED", "SKIPPED"
@@ -130,13 +140,11 @@ tasks.register('bstack-parallel', Test) {
130140

131141
tasks.register('bstack-parallel-devices', Test) {
132142
useTestNG() {
133-
suites 'src/test/resources/conf/runners/testng-browserstack-parallel.xml'
134-
parallel project.property('testngParallel')
135-
threadCount Integer.parseInt(project.property('testngThreadCount'))
136-
listeners.add("com.browserstack.test.utils.BrowserstackTestStatusListener")
143+
dependsOn clean
144+
useDefaultListeners = true
145+
suites 'src/test/resources/conf/runners/testng.xml'
146+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
137147
}
138-
systemProperty "environment", "remote"
139-
systemProperty "testType", "parallel"
140148
testLogging {
141149
events "PASSED", "FAILED", "SKIPPED"
142150
}

0 commit comments

Comments
 (0)