Skip to content

Commit bd9ea11

Browse files
authoredApr 4, 2025··
Merge pull request #34 from rhisav-25/AAP-15642-Add-gradle-config-support-for-junit-4-and-5
Added Gradle config support for JUnit 4 & 5
2 parents 3e0c727 + 76b087f commit bd9ea11

File tree

11 files changed

+342
-8
lines changed

11 files changed

+342
-8
lines changed
 

‎.github/workflows/sanity-workflow.yml

+32
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ jobs:
7272
cd junit-4/ios
7373
mvn compile
7474
mvn test -P sample-local-test -D"browserstack.app"="./LocalSample.ipa"
75+
- name: Run gradle test for junit4 android
76+
run: |
77+
cd junit-4/android
78+
gradle clean sampleTest
79+
- name: Run gradle sample-local-test for junit4 android
80+
run: |
81+
cd junit-4/android
82+
gradle clean sampleLocalTest -D"browserstack.app"="./LocalSample.apk"
83+
- name: Run gradle test for junit4 ios
84+
run: |
85+
cd junit-4/ios
86+
gradle clean sampleTest
87+
- name: Run gradle sample-local-test for junit4 ios
88+
run: |
89+
cd junit-4/ios
90+
gradle clean sampleLocalTest -D"browserstack.app"="./LocalSample.ipa"
7591
- name: Run mvn test for junit5 android
7692
run: |
7793
cd junit-5/android
@@ -92,6 +108,22 @@ jobs:
92108
cd junit-5/ios
93109
mvn compile
94110
mvn test -P sample-local-test -D"browserstack.app"="./LocalSample.ipa"
111+
- name: Run gradle test for junit5 android
112+
run: |
113+
cd junit-5/android
114+
gradle clean sampleTest
115+
- name: Run gradle sample-local-test for junit5 android
116+
run: |
117+
cd junit-5/android
118+
gradle clean sampleLocalTest -D"browserstack.app"="./LocalSample.apk"
119+
- name: Run gradle test for junit5 ios
120+
run: |
121+
cd junit-5/ios
122+
gradle clean sampleTest
123+
- name: Run gradle sample-local-test for junit5 ios
124+
run: |
125+
cd junit-5/ios
126+
gradle clean sampleLocalTest -D"browserstack.app"="./LocalSample.ipa"
95127
- if: always()
96128
uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975
97129
id: status-check-completed

‎.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ local.log
44
.idea
55
*/*/logs
66
*.iml
7+
bstack_*
8+
gradlew*
9+
gradle
10+
.gradle
11+
build
12+
reports

‎README.md

+42-8
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@ These code samples are currently based on:
2121
- For Windows, download latest java version from [here](https://java.com/en/download/) and run the installer executable
2222
- For Mac and Linux, run `java -version` to see what java version is pre-installed. If you want a different version download from [here](https://java.com/en/download/)
2323

24-
2. Maven
24+
2. Maven (Only required if using Maven as the build tool)
25+
2526
- If Maven is not downloaded, download it from [here](https://maven.apache.org/download.cgi)
2627
- For installation, follow the instructions [here](https://maven.apache.org/install.html)
2728

29+
3. Gradle (Only required if using Gradle as the build tool)
30+
31+
- If Gradle is not downloaded, download it from [here](https://gradle.org/releases/)
32+
- For installation, follow the instructions [here](https://gradle.org/install/)
33+
2834
### Install the dependencies
2935

3036
To install the dependencies for JUnit4 tests, run :
@@ -69,11 +75,25 @@ Getting Started with Appium tests in Junit4 and Junit5 on BrowserStack couldn't
6975
7076
- Junit4
7177
- Update `browserstack.yml` file at root level of [Android Junit4 examples](junit-4/android) or [iOS Junit4 examples](junit-4/ios) with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings)
72-
- Run `mvn test -P sample-test`
78+
- **For Maven:** Run the following command to execute tests in the Maven environment:
79+
```sh
80+
mvn test -P sample-test
81+
```
82+
- **For Gradle:** Run the following command to execute tests in the Gradle environment:
83+
```sh
84+
gradle clean sampleTest
85+
```
7386
7487
- Junit5
7588
- Update `browserstack.yml` file at root level of [Android Junit5 examples](junit-5/android) or [iOS Junit5 examples](junit-5/ios) with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings)
76-
- Run `mvn test -P sample-test`
89+
- **For Maven:** Run the following command to execute tests in the Maven environment:
90+
```sh
91+
mvn test -P sample-test
92+
```
93+
- **For Gradle:** Run the following command to execute tests in the Gradle environment:
94+
```sh
95+
gradle clean sampleTest
96+
```
7797
7898
### **Use Local testing for apps that access resources hosted in development or testing environments :**
7999
@@ -83,15 +103,29 @@ Getting Started with Appium tests in Junit4 and Junit5 on BrowserStack couldn't
83103
```
84104
browserstackLocal: true
85105
```
86-
- Run `mvn test -P sample-local-test`
106+
- **For Maven:** Run the following command to execute tests in the Maven environment:
107+
```sh
108+
mvn test -P sample-local-test
109+
```
110+
- **For Gradle:** Run the following command to execute tests in the Gradle environment:
111+
```sh
112+
gradle clean sampleLocalTest
113+
```
87114
88-
- Junit5
89-
- Update `browserstack.yml` file at root level of Android Junit5 examples or iOS Junit5 examples with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings)
90-
- Simply configure the browserstackLocal parameter in the browserstack.yml file accordingly in [Android Junit5 examples](junit-5/android) or [iOS Junit5 examples](junit-5/ios).
115+
- Junit5
116+
- Update `browserstack.yml` file at root level of Android Junit5 examples or iOS Junit5 examples with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings)
117+
- Simply configure the browserstackLocal parameter in the browserstack.yml file accordingly in [Android Junit5 examples](junit-5/android) or [iOS Junit5 examples](junit-5/ios).
91118
```
92119
browserstackLocal: true
93120
```
94-
- Run `mvn test -P sample-local-test`
121+
- **For Maven:** Run the following command to execute tests in the Maven environment:
122+
```sh
123+
mvn test -P sample-local-test
124+
```
125+
- **For Gradle:** Run the following command to execute tests in the Gradle environment:
126+
```sh
127+
gradle clean sampleLocalTest
128+
```
95129
96130
**Note**: If you are facing any issues, refer [Getting Help section](#Getting-Help)
97131

‎junit-4/android/build.gradle

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
plugins {
2+
id 'java'
3+
id 'com.browserstack.gradle-sdk' version "1.1.2"
4+
}
5+
6+
repositories { mavenCentral() }
7+
8+
dependencies {
9+
testImplementation 'junit:junit:4.13.2'
10+
implementation 'commons-io:commons-io:2.11.0'
11+
implementation 'org.seleniumhq.selenium:selenium-java:4.4.0'
12+
implementation 'io.appium:java-client:8.1.1'
13+
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
14+
implementation 'com.browserstack:browserstack-java-sdk:latest.release'
15+
}
16+
17+
group = 'com.browserstack'
18+
version = '1.0-SNAPSHOT'
19+
description = 'junit-browserstack'
20+
sourceCompatibility = '1.8'
21+
22+
def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' }
23+
24+
tasks.withType(JavaCompile) {
25+
options.encoding = 'UTF-8'
26+
}
27+
28+
tasks.withType(Test) {
29+
systemProperties = System.properties
30+
jvmArgs += "-javaagent:${browserstackSDKArtifact.file}"
31+
}
32+
33+
task sampleTest(type: Test) {
34+
dependsOn cleanTest
35+
useJUnit()
36+
37+
include 'com/browserstack/FirstTest*'
38+
39+
jvmArgs "-javaagent:${configurations.testRuntimeClasspath.find { it.name.contains('browserstack-java-sdk') }}"
40+
}
41+
42+
43+
task sampleLocalTest(type: Test) {
44+
dependsOn cleanTest
45+
useJUnit()
46+
47+
include 'com/browserstack/LocalTest*'
48+
49+
jvmArgs "-javaagent:${configurations.testRuntimeClasspath.find { it.name.contains('browserstack-java-sdk') }}"
50+
}

‎junit-4/android/settings.gradle

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}

‎junit-4/ios/build.gradle

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
plugins {
2+
id 'java'
3+
id 'com.browserstack.gradle-sdk' version "1.1.2"
4+
}
5+
6+
repositories { mavenCentral() }
7+
8+
dependencies {
9+
testImplementation 'junit:junit:4.13.2'
10+
implementation 'commons-io:commons-io:2.11.0'
11+
implementation 'org.seleniumhq.selenium:selenium-java:4.4.0'
12+
implementation 'io.appium:java-client:8.1.1'
13+
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
14+
implementation 'com.browserstack:browserstack-java-sdk:latest.release'
15+
}
16+
17+
group = 'com.browserstack'
18+
version = '1.0-SNAPSHOT'
19+
description = 'junit-browserstack'
20+
sourceCompatibility = '1.8'
21+
22+
def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' }
23+
24+
tasks.withType(JavaCompile) {
25+
options.encoding = 'UTF-8'
26+
}
27+
28+
tasks.withType(Test) {
29+
systemProperties = System.properties
30+
jvmArgs += "-javaagent:${browserstackSDKArtifact.file}"
31+
}
32+
33+
task sampleTest(type: Test) {
34+
dependsOn cleanTest
35+
useJUnit()
36+
37+
include 'com/browserstack/FirstTest*'
38+
39+
jvmArgs "-javaagent:${configurations.testRuntimeClasspath.find { it.name.contains('browserstack-java-sdk') }}"
40+
}
41+
42+
43+
task sampleLocalTest(type: Test) {
44+
dependsOn cleanTest
45+
useJUnit()
46+
47+
include 'com/browserstack/LocalTest*'
48+
49+
jvmArgs "-javaagent:${configurations.testRuntimeClasspath.find { it.name.contains('browserstack-java-sdk') }}"
50+
}

‎junit-4/ios/settings.gradle

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}

‎junit-5/android/build.gradle

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
plugins {
2+
id 'java'
3+
id 'com.browserstack.gradle-sdk' version "1.1.2"
4+
}
5+
6+
repositories { mavenCentral() }
7+
8+
dependencies {
9+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
10+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
11+
implementation 'commons-io:commons-io:2.11.0'
12+
implementation 'org.seleniumhq.selenium:selenium-java:4.4.0'
13+
implementation 'io.appium:java-client:8.1.1'
14+
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
15+
implementation 'com.browserstack:browserstack-java-sdk:latest.release'
16+
}
17+
18+
group = 'com.browserstack'
19+
version = '1.0-SNAPSHOT'
20+
description = 'junit-browserstack'
21+
sourceCompatibility = '1.8'
22+
23+
def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' }
24+
25+
tasks.withType(JavaCompile) {
26+
options.encoding = 'UTF-8'
27+
}
28+
29+
tasks.withType(Test) {
30+
systemProperties = System.properties
31+
jvmArgs += "-javaagent:${browserstackSDKArtifact.file}"
32+
}
33+
34+
task sampleTest(type: Test) {
35+
dependsOn cleanTest
36+
useJUnitPlatform()
37+
38+
include 'com/browserstack/FirstTest*'
39+
40+
jvmArgs "-javaagent:${configurations.testRuntimeClasspath.find { it.name.contains('browserstack-java-sdk') }}"
41+
}
42+
43+
44+
task sampleLocalTest(type: Test) {
45+
dependsOn cleanTest
46+
useJUnitPlatform()
47+
48+
include 'com/browserstack/LocalTest*'
49+
50+
jvmArgs "-javaagent:${configurations.testRuntimeClasspath.find { it.name.contains('browserstack-java-sdk') }}"
51+
}

‎junit-5/android/settings.gradle

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}

‎junit-5/ios/build.gradle

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
plugins {
2+
id 'java'
3+
id 'com.browserstack.gradle-sdk' version "1.1.2"
4+
}
5+
6+
repositories { mavenCentral() }
7+
8+
dependencies {
9+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
10+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
11+
implementation 'commons-io:commons-io:2.11.0'
12+
implementation 'org.seleniumhq.selenium:selenium-java:4.4.0'
13+
implementation 'io.appium:java-client:8.1.1'
14+
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
15+
implementation 'com.browserstack:browserstack-java-sdk:latest.release'
16+
}
17+
18+
group = 'com.browserstack'
19+
version = '1.0-SNAPSHOT'
20+
description = 'junit-browserstack'
21+
sourceCompatibility = '1.8'
22+
23+
def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' }
24+
25+
tasks.withType(JavaCompile) {
26+
options.encoding = 'UTF-8'
27+
}
28+
29+
tasks.withType(Test) {
30+
systemProperties = System.properties
31+
jvmArgs += "-javaagent:${browserstackSDKArtifact.file}"
32+
}
33+
34+
task sampleTest(type: Test) {
35+
dependsOn cleanTest
36+
useJUnitPlatform()
37+
38+
include 'com/browserstack/FirstTest*'
39+
40+
jvmArgs "-javaagent:${configurations.testRuntimeClasspath.find { it.name.contains('browserstack-java-sdk') }}"
41+
}
42+
43+
44+
task sampleLocalTest(type: Test) {
45+
dependsOn cleanTest
46+
useJUnitPlatform()
47+
48+
include 'com/browserstack/LocalTest*'
49+
50+
jvmArgs "-javaagent:${configurations.testRuntimeClasspath.find { it.name.contains('browserstack-java-sdk') }}"
51+
}

‎junit-5/ios/settings.gradle

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}

0 commit comments

Comments
 (0)
Please sign in to comment.