Skip to content

Commit cbc043a

Browse files
authored
Merge pull request #60 from Baaryan/master
APS 13484 Add gradle config with updated gradle-sdk plugin for junit 4 & 5
2 parents 6eb990b + 0f88363 commit cbc043a

File tree

8 files changed

+179
-4
lines changed

8 files changed

+179
-4
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ jobs:
1919
matrix:
2020
java: [ '8', '11', '17' ]
2121
os: [ 'macos-latest', 'windows-latest', 'ubuntu-latest' ]
22+
exclude:
23+
- java: '8'
24+
os: 'macos-latest'
2225
name: JUnit Repo ${{ matrix.Java }} - ${{ matrix.os }} Sample
2326
env:
2427
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
@@ -67,6 +70,14 @@ jobs:
6770
cd junit-4
6871
mvn compile
6972
mvn test -P local
73+
- name: Run gradle task sampleTest
74+
run: |
75+
cd junit-4
76+
gradle clean sampleTest
77+
- name: Run gradle task sampleLocalTest
78+
run: |
79+
cd junit-4
80+
gradle clean sampleLocalTest
7081
- name: Run mvn test for junit-5
7182
run: |
7283
cd junit-5
@@ -82,6 +93,14 @@ jobs:
8293
cd junit-5
8394
mvn compile
8495
mvn test -P local
96+
- name: Run gradle task sampleTest
97+
run: |
98+
cd junit-5
99+
gradle clean sampleTest
100+
- name: Run gradle task sampleLocalTest
101+
run: |
102+
cd junit-5
103+
gradle clean sampleLocalTest
85104
- if: always()
86105
uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975
87106
id: status-check-completed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ local.log
2323
*.png
2424
*.txt
2525
**/logs
26+
bstack_*
27+
gradlew*
28+
gradle

junit-4/README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,36 @@
55

66
![JUnit](http://junit.org/junit4/images/junit-logo.png)
77

8-
## Setup
8+
## Using Maven
9+
10+
### Setup
911
* Clone the repo
1012
* Install dependencies `mvn install`
1113
* Update `browserstack.yml` files inside the root directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings).
1214

13-
## Running your tests
15+
### Running your tests
1416
* To run a parallel test, run `mvn test -P sample`
1517
* To run local tests, set `browserStackLocal: true` in `browserstack.yml` and run `mvn test -P local`
1618

1719
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
1820

21+
22+
## Using Gradle
23+
24+
### Prerequisites
25+
- If using Gradle, Java v9+ is required.
26+
27+
### Setup
28+
* Clone the repo
29+
* Update `browserstack.yml` files inside the root directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings).
30+
31+
### Running your tests
32+
* To run a parallel test, run `gradle sampleTest`
33+
* To run local tests, set `browserStackLocal: true` in `browserstack.yml` and run `gradle sampleLocalTest`
34+
35+
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
36+
37+
1938
## Notes
2039
* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate)
2140
* To test on a different set of browsers, check out our [platform configurator](https://www.browserstack.com/automate/java#setting-os-and-browser)

junit-4/build.gradle

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
plugins {
2+
id 'java'
3+
id 'com.browserstack.gradle-sdk' version "1.1.2" // sdk plugin
4+
}
5+
6+
repositories { mavenCentral() }
7+
8+
dependencies {
9+
implementation 'junit:junit:4.13.2'
10+
implementation 'org.seleniumhq.selenium:selenium-java:4.1.4'
11+
implementation 'org.yaml:snakeyaml:2.2'
12+
implementation 'com.browserstack:browserstack-java-sdk:latest.release'
13+
}
14+
15+
group = 'com.browserstack'
16+
version = '1.0-SNAPSHOT'
17+
description = 'junit-browserstack'
18+
sourceCompatibility = '1.8'
19+
20+
def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' }
21+
22+
tasks.withType(JavaCompile) {
23+
options.encoding = 'UTF-8'
24+
}
25+
26+
tasks.withType(Test) {
27+
systemProperties = System.properties
28+
jvmArgs += "-javaagent:${browserstackSDKArtifact.file}"
29+
}
30+
31+
task sampleTest(type: Test) {
32+
useJUnit() {
33+
dependsOn cleanTest
34+
include '**/*BStackSampleTest.*'
35+
}
36+
}
37+
38+
task sampleLocalTest(type: Test) {
39+
useJUnit() {
40+
dependsOn cleanTest
41+
include '**/*BStackLocalTest.*'
42+
}
43+
}

junit-4/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/README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,35 @@ Master branch contains **Selenium 4 - W3C protocol** samples, for **Selenium 3**
44
<a href="https://browserstack.com"><img src="https://avatars.githubusercontent.com/u/1119453?s=200&v=4" width="40" height="40"></a>
55
<a href="https://junit.org/junit5/"><img src="https://camo.githubusercontent.com/abbaedce4b226ea68b0fd43521472b0b146d5ed57956116f69752f43e7ddd7d8/68747470733a2f2f6a756e69742e6f72672f6a756e6974352f6173736574732f696d672f6a756e6974352d6c6f676f2e706e67" width="40" height="40" ></a>
66

7-
## Setup
7+
## Using Maven
8+
9+
### Setup
810
* Clone the repo
911
* Install dependencies `mvn install`
1012
* Update `browserstack.yml` files inside the root directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings).
1113

12-
## Running your tests
14+
### Running your tests
1315
* To run a single test, run `mvn test -P single`
1416
* To run local tests, run `mvn test -P local`
1517

1618
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
1719

20+
## Using Gradle
21+
22+
### Prerequisites
23+
- If using Gradle, Java v9+ is required.
24+
25+
### Setup
26+
- Clone the repository
27+
- Install dependencies `gradle build`
28+
29+
### Running your tests
30+
- To run the single test, run `gradle sampleTest`
31+
- To run local tests, run `gradle sampleLocalTest`
32+
33+
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
34+
35+
1836
## Notes
1937
* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate)
2038
* To test on a different set of browsers, check out our [platform configurator](https://www.browserstack.com/automate/java#setting-os-and-browser)

junit-5/build.gradle

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
plugins {
2+
id 'java'
3+
id 'com.browserstack.gradle-sdk' version "1.1.2" // sdk plugin
4+
}
5+
6+
repositories { mavenCentral() }
7+
8+
dependencies {
9+
implementation 'org.junit.jupiter:junit-jupiter-api:5.9.1'
10+
implementation 'org.junit.jupiter:junit-jupiter-engine:5.9.1'
11+
implementation 'org.seleniumhq.selenium:selenium-java:4.1.4'
12+
implementation 'com.browserstack:browserstack-java-sdk:latest.release'
13+
}
14+
15+
group = 'com.browserstack'
16+
version = '1.0-SNAPSHOT'
17+
description = 'junit-browserstack'
18+
sourceCompatibility = '1.8'
19+
20+
def browserstackSDKArtifact = configurations?.compileClasspath?.resolvedConfiguration?.resolvedArtifacts?.find { it.name == 'browserstack-java-sdk' }
21+
22+
tasks.withType(JavaCompile) {
23+
options.encoding = 'UTF-8'
24+
}
25+
26+
tasks.withType(Test).configureEach { task ->
27+
browserstackSDKArtifact?.file?.with {
28+
task.systemProperties = System.properties
29+
task.jvmArgs += "-javaagent:$it"
30+
}
31+
}
32+
33+
task sampleTest(type: Test) {
34+
dependsOn cleanTest
35+
include '**/*BStackSampleTest.*'
36+
useJUnitPlatform()
37+
}
38+
39+
task sampleLocalTest(type: Test) {
40+
dependsOn cleanTest
41+
include '**/*BStackLocalTest.*'
42+
useJUnitPlatform()
43+
}

junit-5/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)