Skip to content

Commit 415ee04

Browse files
authored
Merge pull request #5 from rhisav-25/AAP-15642-Add-gradle-config-support-for-JBehave
Added Gradle support for JBehave
2 parents 2e9aa09 + 4668525 commit 415ee04

File tree

7 files changed

+183
-4
lines changed

7 files changed

+183
-4
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,22 @@ jobs:
8282
cd ios
8383
mvn compile
8484
mvn test -P sample-test
85+
- name: Run gradle task for android
86+
run: |
87+
cd android
88+
gradle clean sampleTest
89+
- name: Run gradle task sample-local-test for android
90+
run: |
91+
cd android
92+
gradle clean sampleLocalTest -D"browserstack.app"="./LocalSample.apk"
93+
- name: Run gradle task for ios
94+
run: |
95+
cd ios
96+
gradle clean sampleTest
97+
- name: Run gradle task sample-local-test for ios
98+
run: |
99+
cd ios
100+
gradle clean sampleLocalTest -D"browserstack.app"="./LocalSample.ipa"
85101
- if: always()
86102
uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975
87103
id: status-check-completed

.gitignore

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

README.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ This repository demonstrates how to run Appium tests in [JBehave](https://github
1313
- For Windows, download latest java version from [here](https://java.com/en/download/) and run the installer executable
1414
- 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/)
1515

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

20+
3. Gradle (Only required if using Gradle as the build tool)
21+
- If Gradle is not downloaded, download it from [here](https://gradle.org/releases/)
22+
- For installation, follow the instructions [here](https://gradle.org/install/)
23+
2024
### Install the dependencies
2125

2226
To install the dependencies for Android tests, run :
@@ -41,16 +45,30 @@ Getting Started with Appium tests in JBehave on BrowserStack couldn't be easier!
4145
### **Run Sample test :**
4246

4347
- Switch to one of the following directories: [Android examples](android) or [iOS examples](ios)
44-
- Run the following maven command `mvn test -P sample-test`
48+
- **For Maven:** Run the following command to execute tests in the Maven environment:
49+
```sh
50+
mvn test -P sample-test
51+
```
52+
- **For Gradle:** Run the following command to execute tests in the Gradle environment:
53+
```sh
54+
gradle clean sampleTest
55+
```
4556

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

4859
- Simply configure the `browserstackLocal` parameter in the `browserstack.yml` file accordingly in [Android examples](android) or [iOS examples](ios).
4960
```
5061
browserstackLocal: true
5162
```
52-
- You can use the `LocalSample` app provided in both folder [Android examples](android) or [iOS examples](ios) 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`
53-
63+
- You can use the `LocalSample` app provided in both folder [Android examples](android) or [iOS examples](ios) to run your test. Change the app parameter in the `browserstack.yml` file.
64+
- **For Maven:** Run the following command to execute tests in the Maven environment:
65+
```sh
66+
mvn test -P sample-local-test
67+
```
68+
- **For Gradle:** Run the following command to execute tests in the Gradle environment:
69+
```sh
70+
gradle clean sampleLocalTest
71+
```
5472
5573
**Note**: If you are facing any issues, refer [Getting Help section](#Getting-Help)
5674

android/build.gradle

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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.seleniumhq.selenium:selenium-java:4.13.0'
10+
implementation 'io.appium:java-client:8.6.0'
11+
implementation 'org.jbehave:jbehave-core:5.0'
12+
implementation 'org.yaml:snakeyaml:2.0'
13+
implementation 'com.browserstack:browserstack-java-sdk:latest.release'
14+
}
15+
16+
group = 'com.browserstack'
17+
version = '1.0-SNAPSHOT'
18+
description = 'jbehave-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+
jvmArgs += "-javaagent:${browserstackSDKArtifact.file}"
30+
}
31+
32+
task sampleTest(type: Test) {
33+
dependsOn cleanTest
34+
useJUnitPlatform()
35+
36+
include 'com/browserstack/BrowserStackJBehaveRunner*'
37+
38+
systemProperty 'embedder', 'com.browserstack.single.SampleEmbedder'
39+
systemProperty 'stories', 'stories/sample.story'
40+
41+
jvmArgs "-javaagent:${configurations.testRuntimeClasspath.find { it.name.contains('browserstack-java-sdk') }}"
42+
}
43+
44+
45+
task sampleLocalTest(type: Test) {
46+
dependsOn cleanTest
47+
useJUnitPlatform()
48+
49+
include 'com/browserstack/BrowserStackJBehaveRunner*'
50+
51+
systemProperty 'embedder', 'com.browserstack.local.LocalEmbedder'
52+
systemProperty 'stories', 'stories/local.story'
53+
54+
jvmArgs "-javaagent:${configurations.testRuntimeClasspath.find { it.name.contains('browserstack-java-sdk') }}"
55+
}

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+
}

ios/build.gradle

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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.seleniumhq.selenium:selenium-java:4.13.0'
10+
implementation 'io.appium:java-client:8.6.0'
11+
implementation 'org.jbehave:jbehave-core:5.0'
12+
implementation 'org.yaml:snakeyaml:2.0'
13+
implementation 'com.browserstack:browserstack-java-sdk:latest.release'
14+
}
15+
16+
group = 'com.browserstack'
17+
version = '1.0-SNAPSHOT'
18+
description = 'jbehave-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+
jvmArgs += "-javaagent:${browserstackSDKArtifact.file}"
30+
}
31+
32+
task sampleTest(type: Test) {
33+
dependsOn cleanTest
34+
useJUnitPlatform()
35+
36+
include 'com/browserstack/BrowserStackJBehaveRunner*'
37+
38+
systemProperty 'embedder', 'com.browserstack.single.SampleEmbedder'
39+
systemProperty 'stories', 'stories/sample.story'
40+
41+
jvmArgs "-javaagent:${configurations.testRuntimeClasspath.find { it.name.contains('browserstack-java-sdk') }}"
42+
}
43+
44+
45+
task sampleLocalTest(type: Test) {
46+
dependsOn cleanTest
47+
useJUnitPlatform()
48+
49+
include 'com/browserstack/BrowserStackJBehaveRunner*'
50+
51+
systemProperty 'embedder', 'com.browserstack.local.LocalEmbedder'
52+
systemProperty 'stories', 'stories/local.story'
53+
54+
jvmArgs "-javaagent:${configurations.testRuntimeClasspath.find { it.name.contains('browserstack-java-sdk') }}"
55+
}

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)