Skip to content

Commit debe5ef

Browse files
Merge pull request #51 from Baaryan/master
APS 13484 Add gradle config with updated gradle-sdk plugin for serenity
2 parents 56c0dd3 + 0299390 commit debe5ef

5 files changed

Lines changed: 122 additions & 1 deletion

File tree

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

Lines changed: 9 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: Serenity Repo ${{ matrix.Java }} - ${{ matrix.os }} Sample
2326
env:
2427
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
@@ -64,6 +67,12 @@ jobs:
6467
run: |
6568
mvn compile
6669
mvn verify -P sample-test
70+
- name: Run gradle task sampleTest
71+
run: |
72+
gradle clean sampleTest
73+
- name: Run gradle task sampleLocalTest
74+
run: |
75+
gradle clean sampleLocalTest
6776
- if: always()
6877
uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975
6978
id: status-check-completed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ pom.xml.versionsBackup
1818
pom.xml.next
1919
release.properties
2020

21+
##########################
22+
## Gradle
23+
##########################
24+
.Gradle
25+
gradle
26+
gradlew*
27+
bstack_*
28+
2129
##########################
2230
## IntelliJ
2331
##########################

README.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<img src="https://serenity-bdd.info/wp-content/uploads/elementor/thumbs/serenity-bdd-pac9onzlqv9ebi90cpg4zsqnp28x4trd1adftgkwbq.png" height = "100">
88

9-
## Run Sample build
9+
## Using Maven
1010
### Setup
1111
* Clone the repo
1212
* Replace YOUR_USERNAME and YOUR_ACCESS_KEY with your BrowserStack access credentials in browserstack.yml.
@@ -70,6 +70,54 @@ This repository uses the BrowserStack SDK to run tests on BrowserStack. Follow t
7070
```
7171
* Install dependencies `mvn compile`
7272

73+
## Using Gradle
74+
75+
### Prerequisites
76+
- If using Gradle, Java v9+ is required.
77+
78+
### Setup
79+
* Clone the repo
80+
* Replace YOUR_USERNAME and YOUR_ACCESS_KEY with your BrowserStack access credentials in browserstack.yml.
81+
82+
### Running your tests
83+
84+
- Clone the repository
85+
- To run the test suite having cross-platform with parallelization, run `gradle sampleTest`
86+
- To run local tests, run `gradle sampleLocalTest`
87+
88+
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
89+
90+
### Integrate your test suite
91+
92+
This repository uses the BrowserStack SDK to run tests on BrowserStack. Follow the steps below to install the SDK in your test suite and run tests on BrowserStack:
93+
94+
* Following are the changes required in `build.gradle` -
95+
* Add `id 'com.browserstack.gradle-sdk' version "1.1.2"` in plugins
96+
* Add `implementation 'com.browserstack:browserstack-java-sdk:latest.release'` in dependencies
97+
* Fetch Artifact Information and add `jvmArgs` property in tasks *SampleTest* and *SampleLocalTest* :
98+
```
99+
def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' }
100+
101+
task sampleTest(type: Test) {
102+
dependsOn cleanTest
103+
include '**/SampleTest.**'
104+
jvmArgs "-javaagent:${browserstackSDKArtifact.file}"
105+
useJUnitPlatform()
106+
}
107+
```
108+
* Following are the changes required in `settings.gradle` -
109+
* Add `resolutionStrategy` inside `pluginManagement`
110+
* Inside `resolutionStrategy` add the plugin `id` as `com.browserstack.gradle-sdk` along with module `version`
111+
```
112+
eachPlugin {
113+
if (requested.id.id == "com.browserstack.gradle-sdk") {
114+
useModule("com.browserstack:gradle-sdk:1.1.2")
115+
}
116+
}
117+
```
118+
119+
* Install dependencies and run test `gradle sampleTest`
120+
73121
## Notes
74122
* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate)
75123
* You can export the environment variables for the Username and Access Key of your BrowserStack account

build.gradle

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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.vintage:junit-vintage-engine:5.8.2'
10+
implementation 'net.serenity-bdd:serenity-core:3.3.4'
11+
implementation 'net.serenity-bdd:serenity-cucumber:3.3.4'
12+
implementation 'com.browserstack:browserstack-java-sdk:latest.release'
13+
}
14+
15+
group = 'com.browserstack'
16+
version = '1.0-SNAPSHOT'
17+
description = 'serenity-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+
dependsOn cleanTest
33+
include '**/SampleTest.**'
34+
useJUnitPlatform()
35+
}
36+
37+
task sampleLocalTest(type: Test) {
38+
dependsOn cleanTest
39+
include '**/LocalTest.**'
40+
useJUnitPlatform()
41+
}

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)