Skip to content

Commit 097759a

Browse files
samirans89Abhi Singh
andauthored
jenkins fixes (#25)
* jenkins fixes * jenkins fixes readme * updates BrowserStack SDK --------- Co-authored-by: Abhi Singh <abhi.s@browserstack.com>
1 parent 15895b1 commit 097759a

10 files changed

Lines changed: 168 additions & 23 deletions

Jenkinsfile

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
2+
3+
node {
4+
try {
5+
properties([
6+
parameters([
7+
credentials(credentialType: 'com.browserstack.automate.ci.jenkins.BrowserStackCredentials', defaultValue: '', description: 'Select your BrowserStack Username', name: 'BROWSERSTACK_USERNAME', required: true),
8+
choice(
9+
choices: [
10+
'bstack-single',
11+
'bstack-parallel',
12+
'bstack-parallel-browsers',
13+
'bstack-local',
14+
'bstack-local-parallel',
15+
'bstack-local-parallel-browsers'
16+
],
17+
description: 'Select the test you would like to run',
18+
name: 'TEST_TYPE'
19+
)
20+
])
21+
])
22+
23+
stage('Pull code from Github') {
24+
dir('test') {
25+
git branch: 'main', changelog: false, poll: false, url: 'https://github.com/browserstack/browserstack-examples-testng'
26+
}
27+
}
28+
29+
stage('Run Test') {
30+
browserstack(credentialsId: "${params.BROWSERSTACK_USERNAME}") {
31+
def user = "${env.BROWSERSTACK_USERNAME}"
32+
if (user.contains('-')) {
33+
user = user.substring(0, user.lastIndexOf('-'))
34+
}
35+
withEnv(['BROWSERSTACK_USERNAME=' + user]) {
36+
sh label: '', returnStatus: true, script:'''#!/bin/bash -l
37+
cd test
38+
ln src/test/resources/conf/capabilities/${TEST_TYPE}.yml browserstack.yml
39+
mvn clean test -P ${TEST_TYPE} '''
40+
}
41+
}
42+
}
43+
44+
stage('Generate Report') {
45+
browserStackReportPublisher 'automate'
46+
}
47+
}catch (e) {
48+
currentBuild.result = 'FAILURE'
49+
echo e
50+
throw e
51+
} finally {
52+
notifySlack(currentBuild.result)
53+
}
54+
}
55+
def notifySlack(String buildStatus = 'STARTED') {
56+
// Build status of null means success.
57+
buildStatus = buildStatus ?: 'SUCCESS'
58+
59+
def color
60+
61+
if (buildStatus == 'STARTED') {
62+
color = '#D4DADF'
63+
} else if (buildStatus == 'SUCCESS') {
64+
color = '#BDFFC3'
65+
} else if (buildStatus == 'UNSTABLE') {
66+
color = '#FFFE89'
67+
} else {
68+
color = '#FF9FA1'
69+
}
70+
71+
def msg = "${buildStatus}: `${env.JOB_NAME}` #${env.BUILD_NUMBER}:\n${env.BUILD_URL}"
72+
if (buildStatus != 'STARTED' && buildStatus != 'SUCCESS') {
73+
slackSend(color: color, message: msg)
74+
}
75+
}

README.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ Note:
171171

172172
### Run a specific test on BrowserStack
173173

174-
In this section, we will run a single test on Chrome browser on Browserstack. To change test capabilities for this configuration, please refer to the `browserstack-single.yml` file.
174+
In this section, we will run a single test on Chrome browser on Browserstack. To change test capabilities for this configuration, please refer to the `bstack-single.yml` file.
175175

176176
- How to run the test?
177177

@@ -181,13 +181,13 @@ In this section, we will run a single test on Chrome browser on Browserstack. To
181181

182182
```sh
183183
rm -f -- browserstack.yml
184-
ln src/test/resources/conf/capabilities/browserstack-single.yml browserstack.yml
184+
ln src/test/resources/conf/capabilities/bstack-single.yml browserstack.yml
185185
```
186186

187187
- For Windows:
188188

189189
```sh
190-
del /f "browserstack.yml" && copy /y .\src\test\resources\conf\capabilities\browserstack-single.yml browserstack.yml
190+
del /f "browserstack.yml" && copy /y .\src\test\resources\conf\capabilities\bstack-single.yml browserstack.yml
191191
```
192192

193193
To run the default test scenario (e.g. End to End Scenario) on your own machine, use the following command:
@@ -226,7 +226,7 @@ In this section, we will run a single test on Chrome browser on Browserstack. To
226226

227227
### Run the entire test suite in parallel on a single BrowserStack browser
228228

229-
In this section, we will run the tests in parallel on a single browser on Browserstack. Refer to `browserstack-parallel.yml` file to change test capabilities for this configuration.
229+
In this section, we will run the tests in parallel on a single browser on Browserstack. Refer to `bstack-parallel.yml` file to change test capabilities for this configuration.
230230

231231
- How to run the test?
232232

@@ -236,13 +236,13 @@ In this section, we will run the tests in parallel on a single browser on Browse
236236

237237
```sh
238238
rm -f -- browserstack.yml
239-
ln src/test/resources/conf/capabilities/browserstack-parallel.yml browserstack.yml
239+
ln src/test/resources/conf/capabilities/bstack-parallel.yml browserstack.yml
240240
```
241241

242242
- For Windows:
243243

244244
```sh
245-
del /f "browserstack.yml" && copy /y .\src\test\resources\conf\capabilities\browserstack-parallel.yml browserstack.yml
245+
del /f "browserstack.yml" && copy /y .\src\test\resources\conf\capabilities\bstack-parallel.yml browserstack.yml
246246
```
247247

248248
To run the entire test suite in parallel on a single BrowserStack browser, use the following command:
@@ -265,21 +265,21 @@ In this section, we will run the tests in parallel on a single browser on Browse
265265

266266
### Run the entire test suite in parallel on multiple BrowserStack browsers
267267

268-
In this section, we will run the tests in parallel on multiple browsers on Browserstack. Refer to the `browserstack-parallel-browsers.yml` file to change test capabilities for this configuration.
268+
In this section, we will run the tests in parallel on multiple browsers on Browserstack. Refer to the `bstack-parallel-browsers.yml` file to change test capabilities for this configuration.
269269

270270
- Copy the capabilities to the root of the project:
271271

272272
- For \*nix based and Mac machines:
273273

274274
```sh
275275
rm -f -- browserstack.yml
276-
ln src/test/resources/conf/capabilities/browserstack-parallel-browsers.yml browserstack.yml
276+
ln src/test/resources/conf/capabilities/bstack-parallel-browsers.yml browserstack.yml
277277
```
278278

279279
- For Windows:
280280

281281
```sh
282-
del /f "browserstack.yml" && copy /y .\src\test\resources\conf\capabilities\browserstack-parallel-browsers.yml browserstack.yml
282+
del /f "browserstack.yml" && copy /y .\src\test\resources\conf\capabilities\bstack-parallel-browsers.yml browserstack.yml
283283
```
284284

285285
- How to run the test?
@@ -289,13 +289,13 @@ In this section, we will run the tests in parallel on multiple browsers on Brows
289289
Maven:
290290

291291
```sh
292-
mvn clean test -P bstack-parallel
292+
mvn clean test -P bstack-parallel-browsers
293293
```
294294

295295
Gradle:
296296

297297
```sh
298-
gradle clean bstack-parallel
298+
gradle clean bstack-parallel-browsers
299299
```
300300

301301
### [Web application hosted on internal environment] Running your tests on BrowserStack using BrowserStackLocal
@@ -307,7 +307,7 @@ In this section, we will run the tests in parallel on multiple browsers on Brows
307307
git clone https://github.com/browserstack/browserstack-demo-app
308308
```
309309
- Please follow the README.md on the BrowserStack demo application repository to install and start the dev server on localhost.
310-
- In this section, we will run a single test case to test the BrowserStack Demo app hosted on your local machine i.e. localhost. Refer to the `browserstack-local.yml` file to change test capabilities for this configuration.
310+
- In this section, we will run a single test case to test the BrowserStack Demo app hosted on your local machine i.e. localhost. Refer to the `bstack-local.yml` file to change test capabilities for this configuration.
311311
- 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).
312312
- Further details for successfully creating a BrowserStackLocal connection can be found here:
313313

@@ -324,13 +324,13 @@ In this section, we will run the tests in parallel on multiple browsers on Brows
324324

325325
```sh
326326
rm -f -- browserstack.yml
327-
ln src/test/resources/conf/capabilities/browserstack-local.yml browserstack.yml
327+
ln src/test/resources/conf/capabilities/bstack-local.yml browserstack.yml
328328
```
329329

330330
- For Windows:
331331

332332
```sh
333-
del /f "browserstack.yml" && copy /y .\src\test\resources\conf\capabilities\browserstack-local.yml browserstack.yml
333+
del /f "browserstack.yml" && copy /y .\src\test\resources\conf\capabilities\bstack-local.yml browserstack.yml
334334
```
335335

336336
- To run the default test scenario (e.g. End to End Scenario) on a single BrowserStack browser using BrowserStackLocal, use the following command:
@@ -368,7 +368,7 @@ In this section, we will run the tests in parallel on multiple browsers on Brows
368368

369369
### [Web application hosted on internal environment] Run the entire test suite in parallel on a single BrowserStack browser using BrowserStackLocal
370370

371-
In this section, we will run the test cases to test the internally hosted website in parallel on a single browser on Browserstack. Refer to the `browserstack-local-parallel.yml` file to change test capabilities for this configuration.
371+
In this section, we will run the test cases to test the internally hosted website in parallel on a single browser on Browserstack. Refer to the `bstack-local-parallel.yml` file to change test capabilities for this configuration.
372372

373373
- How to run the test?
374374

@@ -378,13 +378,13 @@ In this section, we will run the test cases to test the internally hosted websit
378378

379379
```sh
380380
rm -f -- browserstack.yml
381-
ln src/test/resources/conf/capabilities/browserstack-local-parallel.yml browserstack.yml
381+
ln src/test/resources/conf/capabilities/bstack-local-parallel.yml browserstack.yml
382382
```
383383

384384
- For Windows:
385385

386386
```sh
387-
del /f "browserstack.yml" && copy /y .\src\test\resources\conf\capabilities\browserstack-local-parallel.yml browserstack.yml
387+
del /f "browserstack.yml" && copy /y .\src\test\resources\conf\capabilities\bstack-local-parallel.yml browserstack.yml
388388
```
389389

390390
To run the entire test suite in parallel on a single BrowserStack browser using BrowserStackLocal, use the following command:
@@ -406,7 +406,7 @@ In this section, we will run the test cases to test the internally hosted websit
406406

407407
### [Web application hosted on internal environment] Run the entire test suite in parallel on multiple BrowserStack browser using BrowserStackLocal
408408

409-
In this section, we will run the test cases to test the internally hosted website in parallel on multiple browsers on Browserstack. Refer to the `browserstack-local-parallel-browsers.yml` file to change test capabilities for this configuration.
409+
In this section, we will run the test cases to test the internally hosted website in parallel on multiple browsers on Browserstack. Refer to the `bstack-local-parallel-browsers.yml` file to change test capabilities for this configuration.
410410

411411
- How to run the test?
412412

@@ -416,27 +416,27 @@ In this section, we will run the test cases to test the internally hosted websit
416416

417417
```sh
418418
rm -f -- browserstack.yml
419-
ln src/test/resources/conf/capabilities/browserstack-local-parallel-browsers.yml browserstack.yml
419+
ln src/test/resources/conf/capabilities/bstack-local-parallel-browsers.yml browserstack.yml
420420
```
421421

422422
- For Windows:
423423

424424
```sh
425-
del /f "browserstack.yml" && copy /y .\src\test\resources\conf\capabilities\browserstack-local-parallel-browsers.yml browserstack.yml
425+
del /f "browserstack.yml" && copy /y .\src\test\resources\conf\capabilities\bstack-local-parallel-browsers.yml browserstack.yml
426426
```
427427

428428
To run the entire test suite in parallel on a single BrowserStack browser using BrowserStackLocal, use the following command:
429429

430430
Maven:
431431

432432
```sh
433-
mvn clean test -P bstack-local-parallel
433+
mvn clean test -P bstack-local-parallel-browsers
434434
```
435435

436436
Gradle:
437437

438438
```sh
439-
gradle clean bstack-local-parallel
439+
gradle clean bstack-local-parallel-browsers
440440
```
441441

442442
- Output

build.gradle

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@ tasks.register('bstack-parallel', Test) {
9494
}
9595
}
9696

97+
tasks.register('bstack-parallel-browsers', Test) {
98+
useTestNG() {
99+
dependsOn clean
100+
useDefaultListeners = true
101+
suites 'src/test/resources/conf/runners/testng.xml'
102+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
103+
}
104+
systemProperty "browserstack-local", "false"
105+
systemProperty "testType", "parallel"
106+
testLogging {
107+
events "PASSED", "FAILED", "SKIPPED"
108+
}
109+
}
97110

98111
tasks.register('percy', Test) {
99112
useTestNG() {
@@ -148,3 +161,16 @@ tasks.register('bstack-local-parallel', Test) {
148161
events "PASSED", "FAILED", "SKIPPED"
149162
}
150163
}
164+
165+
tasks.register('bstack-local-parallel-browsers', Test) {
166+
useTestNG() {
167+
dependsOn clean
168+
useDefaultListeners = true
169+
suites 'src/test/resources/conf/runners/testng.xml'
170+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
171+
}
172+
systemProperty "browserstack-local", "true"
173+
testLogging {
174+
events "PASSED", "FAILED", "SKIPPED"
175+
}
176+
}

pom.xml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
<dependency>
100100
<groupId>com.browserstack</groupId>
101101
<artifactId>browserstack-java-sdk</artifactId>
102-
<version>1.1.1</version>
102+
<version>1.3.0</version>
103103
<scope>compile</scope>
104104
</dependency>
105105
</dependencies>
@@ -211,6 +211,28 @@
211211
</plugins>
212212
</build>
213213
</profile>
214+
<profile>
215+
<id>bstack-parallel-browsers</id>
216+
<build>
217+
<plugins>
218+
<plugin>
219+
<groupId>org.apache.maven.plugins</groupId>
220+
<artifactId>maven-surefire-plugin</artifactId>
221+
<configuration>
222+
<argLine>
223+
-javaagent:${com.browserstack:browserstack-java-sdk:jar}
224+
</argLine>
225+
<systemPropertyVariables>
226+
<browserstack-local>false</browserstack-local>
227+
</systemPropertyVariables>
228+
<suiteXmlFiles>
229+
<suiteXmlFile>src/test/resources/conf/runners/testng.xml</suiteXmlFile>
230+
</suiteXmlFiles>
231+
</configuration>
232+
</plugin>
233+
</plugins>
234+
</build>
235+
</profile>
214236
<profile>
215237
<id>percy</id>
216238
<build>
@@ -305,5 +327,27 @@
305327
</plugins>
306328
</build>
307329
</profile>
330+
<profile>
331+
<id>bstack-local-parallel-browsers</id>
332+
<build>
333+
<plugins>
334+
<plugin>
335+
<groupId>org.apache.maven.plugins</groupId>
336+
<artifactId>maven-surefire-plugin</artifactId>
337+
<configuration>
338+
<argLine>
339+
-javaagent:${com.browserstack:browserstack-java-sdk:jar}
340+
</argLine>
341+
<systemPropertyVariables>
342+
<browserstack-local>true</browserstack-local>
343+
</systemPropertyVariables>
344+
<suiteXmlFiles>
345+
<suiteXmlFile>src/test/resources/conf/runners/testng.xml</suiteXmlFile>
346+
</suiteXmlFiles>
347+
</configuration>
348+
</plugin>
349+
</plugins>
350+
</build>
351+
</profile>
308352
</profiles>
309353
</project>

src/test/resources/conf/capabilities/browserstack-local-parallel-browsers.yml renamed to src/test/resources/conf/capabilities/bstack-local-parallel-browsers.yml

File renamed without changes.

src/test/resources/conf/capabilities/browserstack-local-parallel.yml renamed to src/test/resources/conf/capabilities/bstack-local-parallel.yml

File renamed without changes.

src/test/resources/conf/capabilities/browserstack-local.yml renamed to src/test/resources/conf/capabilities/bstack-local.yml

File renamed without changes.

src/test/resources/conf/capabilities/browserstack-parallel-browsers.yml renamed to src/test/resources/conf/capabilities/bstack-parallel-browsers.yml

File renamed without changes.

src/test/resources/conf/capabilities/browserstack-parallel.yml renamed to src/test/resources/conf/capabilities/bstack-parallel.yml

File renamed without changes.

src/test/resources/conf/capabilities/browserstack-single.yml renamed to src/test/resources/conf/capabilities/bstack-single.yml

File renamed without changes.

0 commit comments

Comments
 (0)