Skip to content

Commit 0ee8386

Browse files
committed
Added Gradle config support for JUnit 4 & 5
1 parent 3e0c727 commit 0ee8386

File tree

11 files changed

+311
-3
lines changed

11 files changed

+311
-3
lines changed

.github/workflows/sanity-workflow.yml

Lines changed: 32 additions & 0 deletions
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 junit4 android
116+
run: |
117+
cd junit-5/android
118+
gradle clean sampleLocalTest -D"browserstack.app"="./LocalSample.apk"
119+
- name: Run gradle test for junit4 ios
120+
run: |
121+
cd junit-5/ios
122+
gradle clean sampleTest
123+
- name: Run gradle sample-local-test for junit4 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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ These code samples are currently based on:
2525
- If Maven is not downloaded, download it from [here](https://maven.apache.org/download.cgi)
2626
- For installation, follow the instructions [here](https://maven.apache.org/install.html)
2727

28+
3. Gradle
29+
- If Gradle is not downloaded, download it from [here](https://gradle.org/releases/)
30+
- For installation, follow the instructions [here](https://gradle.org/install/)
31+
2832
### Install the dependencies
2933

3034
To install the dependencies for JUnit4 tests, run :
@@ -69,11 +73,13 @@ Getting Started with Appium tests in Junit4 and Junit5 on BrowserStack couldn't
6973
7074
- Junit4
7175
- 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`
76+
- Run `mvn test -P sample-test` to run in maven enviroment.
77+
- Run `gradle clean sampleTest` to run in gradle enviroment.
7378
7479
- Junit5
7580
- 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)
7681
- Run `mvn test -P sample-test`
82+
- Run `gradle clean sampleTest` to run in gradle enviroment.
7783
7884
### **Use Local testing for apps that access resources hosted in development or testing environments :**
7985
@@ -83,15 +89,17 @@ Getting Started with Appium tests in Junit4 and Junit5 on BrowserStack couldn't
8389
```
8490
browserstackLocal: true
8591
```
86-
- Run `mvn test -P sample-local-test`
92+
- Run `mvn test -P sample-local-test` to run in maven enviroment.
93+
- Run `gradle clean sampleLocalTest` to run in gradle enviroment.
8794
8895
- Junit5
8996
- 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)
9097
- 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).
9198
```
9299
browserstackLocal: true
93100
```
94-
- Run `mvn test -P sample-local-test`
101+
- Run `mvn test -P sample-local-test` to run in maven enviroment.
102+
- Run `gradle clean sampleLocalTest` to run in gradle enviroment.
95103
96104
**Note**: If you are facing any issues, refer [Getting Help section](#Getting-Help)
97105

junit-4/android/build.gradle

Lines changed: 50 additions & 0 deletions
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

Lines changed: 15 additions & 0 deletions
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

Lines changed: 50 additions & 0 deletions
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

Lines changed: 15 additions & 0 deletions
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

Lines changed: 51 additions & 0 deletions
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

Lines changed: 15 additions & 0 deletions
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

Lines changed: 51 additions & 0 deletions
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

Lines changed: 15 additions & 0 deletions
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)