Skip to content

Commit b6b5da5

Browse files
committed
Add Gradle support for TestNG and Appium
1 parent 594796a commit b6b5da5

File tree

7 files changed

+165
-0
lines changed

7 files changed

+165
-0
lines changed

.github/workflows/maven-workflow-run.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ jobs:
6767
cd android/testng-examples
6868
mvn compile
6969
mvn test -P sample-local-test -D"browserstack.app"="./LocalSample.apk"
70+
- name: Run Gradle test for testng Android
71+
run: |
72+
cd android/testng-examples
73+
gradle clean sampleTest
74+
75+
- name: Run Gradle profile sampleTest for testng Android
76+
run: |
77+
cd android/testng-examples
78+
gradle clean sampleLocalTest
79+
80+
- name: Run Gradle profile sampleLocalTest for testng Android
81+
run: |
82+
cd android/testng-examples
83+
gradle clean sampleLocalTest -Dbrowserstack.app=./LocalSample.apk
7084
- name: Run mvn test for testng ios
7185
run: |
7286
cd ios/testng-examples
@@ -82,6 +96,20 @@ jobs:
8296
cd ios/testng-examples
8397
mvn compile
8498
mvn test -P sample-local-test -D"browserstack.app"="./LocalSample.ipa"
99+
- name: Run Gradle test for testng ios
100+
run: |
101+
cd ios/testng-examples
102+
gradle clean sampleTest
103+
104+
- name: Run Gradle profile sampleTest for testng ios
105+
run: |
106+
cd ios/testng-examples
107+
gradle clean sampleLocalTest
108+
109+
- name: Run Gradle profile sampleLocalTest for testng ios
110+
run: |
111+
cd ios/testng-examples
112+
gradle clean sample-local-test -D"browserstack.app"="./LocalSample.ipa"
85113
- if: always()
86114
uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975
87115
id: status-check-completed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ local.log
55
*.iml
66
**/logs/*
77
.DS_Store
8+
build
9+
gradle
10+
.gradle
11+
gradlew*

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ This repository demonstrates how to run Appium tests in [TestNG](http://testng.o
1818
- If Maven is not downloaded, download it from [here](https://maven.apache.org/download.cgi)
1919
- For installation, follow the instructions [here](https://maven.apache.org/install.html)
2020

21+
3. Gradle
22+
- If Gradle is not downloaded, download it from [here](https://gradle.org/releases/)
23+
- For installation, follow the instructions [here](https://gradle.org/install/)
24+
2125
### Install the dependencies
2226

2327
To install the dependencies for Android tests, run :
@@ -43,6 +47,7 @@ Getting Started with Appium tests in TestNg on BrowserStack couldn't be easier!
4347

4448
- Switch to one of the following directories: [Android examples](android/testng-examples) or [iOS examples](ios/testng-examples)
4549
- Run the following maven command `mvn test -P sample-test`
50+
- Run the following gradle command `gradle clean sampleTest`
4651

4752
### **Use Local testing for apps that access resources hosted in development or testing environments :**
4853

@@ -52,6 +57,8 @@ Getting Started with Appium tests in TestNg on BrowserStack couldn't be easier!
5257
```
5358
- You can use the `LocalSample` app provided in both folder [Android examples](android/testng-examples) or [iOS examples](ios/testng-examples) to run your test. Change the app parameter in the `browserstack.yml` file and run the tests with the following command: `mvn test -P sample-local-test`
5459

60+
-similarly for gradle you can do :- gradle clean sampleLocalTest
61+
5562

5663
**Note**: If you are facing any issues, refer [Getting Help section](#Getting-Help)
5764

android/testng-examples/build.gradle

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
plugins {
2+
id 'java'
3+
}
4+
5+
repositories { mavenCentral() }
6+
7+
dependencies {
8+
testImplementation 'org.testng:testng:7.5'
9+
implementation 'org.seleniumhq.selenium:selenium-java:4.13.0'
10+
implementation 'io.appium:java-client:8.6.0'
11+
implementation 'commons-io:commons-io:2.11.0'
12+
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
13+
implementation 'com.browserstack:browserstack-java-sdk:latest.release'
14+
}
15+
16+
group = 'com.browserstack'
17+
version = '1.0-SNAPSHOT'
18+
description = 'testng-browserstack'
19+
sourceCompatibility = '1.8'
20+
21+
def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' }
22+
23+
tasks.withType(JavaCompile) {
24+
options.encoding = 'UTF-8'
25+
}
26+
27+
tasks.withType(Test) {
28+
systemProperties = System.properties
29+
}
30+
31+
task sampleTest(type: Test) {
32+
useTestNG() {
33+
dependsOn cleanTest
34+
useDefaultListeners = true
35+
suites "src/test/resources/com/browserstack/sample-test.testng.xml"
36+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
37+
}
38+
}
39+
40+
task sampleLocalTest(type: Test) {
41+
useTestNG() {
42+
dependsOn cleanTest
43+
useDefaultListeners = true
44+
suites "src/test/resources/com/browserstack/sample-local-test.testng.xml"
45+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
46+
}
47+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pluginManagement {
2+
repositories {
3+
mavenCentral()
4+
mavenLocal()
5+
gradlePluginPortal()
6+
}
7+
8+
resolutionStrategy {
9+
eachPlugin {
10+
if (requested.id.id == "com.browserstack.gradle-sdk") {
11+
useModule("com.browserstack:gradle-sdk:1.1.2")
12+
}
13+
}
14+
}
15+
}
16+
rootProject.name = 'testng-browserstack-android'

ios/testng-examples/build.gradle

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
plugins {
2+
id 'java'
3+
}
4+
5+
repositories { mavenCentral() }
6+
7+
dependencies {
8+
testImplementation 'org.testng:testng:7.5'
9+
implementation 'org.seleniumhq.selenium:selenium-java:4.13.0'
10+
implementation 'io.appium:java-client:8.6.0'
11+
implementation 'commons-io:commons-io:2.11.0'
12+
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
13+
implementation 'com.browserstack:browserstack-java-sdk:latest.release'
14+
}
15+
16+
group = 'com.browserstack'
17+
version = '1.0-SNAPSHOT'
18+
description = 'testng-browserstack'
19+
sourceCompatibility = '1.8'
20+
21+
def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' }
22+
23+
tasks.withType(JavaCompile) {
24+
options.encoding = 'UTF-8'
25+
}
26+
27+
tasks.withType(Test) {
28+
systemProperties = System.properties
29+
}
30+
31+
task sampleTest(type: Test) {
32+
useTestNG() {
33+
dependsOn cleanTest
34+
useDefaultListeners = true
35+
suites "src/test/resources/com/browserstack/sample-test.testng.xml"
36+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
37+
}
38+
}
39+
40+
task sampleLocalTest(type: Test) {
41+
useTestNG() {
42+
dependsOn cleanTest
43+
useDefaultListeners = true
44+
suites "src/test/resources/com/browserstack/sample-local-test.testng.xml"
45+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
46+
}
47+
}

ios/testng-examples/settings.gradle

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pluginManagement {
2+
repositories {
3+
mavenCentral()
4+
mavenLocal()
5+
gradlePluginPortal()
6+
}
7+
8+
resolutionStrategy {
9+
eachPlugin {
10+
if (requested.id.id == "com.browserstack.gradle-sdk") {
11+
useModule("com.browserstack:gradle-sdk:1.1.2")
12+
}
13+
}
14+
}
15+
}
16+
rootProject.name = 'testng-browserstack-ios'

0 commit comments

Comments
 (0)