From b6b5da5e703810d730e896a9272fbc392d2535cd Mon Sep 17 00:00:00 2001 From: rhisav-25 Date: Tue, 25 Mar 2025 14:09:16 +0000 Subject: [PATCH 1/2] Add Gradle support for TestNG and Appium --- .github/workflows/maven-workflow-run.yml | 28 ++++++++++++++ .gitignore | 4 ++ README.md | 7 ++++ android/testng-examples/build.gradle | 47 ++++++++++++++++++++++++ android/testng-examples/settings.gradle | 16 ++++++++ ios/testng-examples/build.gradle | 47 ++++++++++++++++++++++++ ios/testng-examples/settings.gradle | 16 ++++++++ 7 files changed, 165 insertions(+) create mode 100644 android/testng-examples/build.gradle create mode 100644 android/testng-examples/settings.gradle create mode 100644 ios/testng-examples/build.gradle create mode 100644 ios/testng-examples/settings.gradle diff --git a/.github/workflows/maven-workflow-run.yml b/.github/workflows/maven-workflow-run.yml index 1682128..bbeffa3 100644 --- a/.github/workflows/maven-workflow-run.yml +++ b/.github/workflows/maven-workflow-run.yml @@ -67,6 +67,20 @@ jobs: cd android/testng-examples mvn compile mvn test -P sample-local-test -D"browserstack.app"="./LocalSample.apk" + - name: Run Gradle test for testng Android + run: | + cd android/testng-examples + gradle clean sampleTest + + - name: Run Gradle profile sampleTest for testng Android + run: | + cd android/testng-examples + gradle clean sampleLocalTest + + - name: Run Gradle profile sampleLocalTest for testng Android + run: | + cd android/testng-examples + gradle clean sampleLocalTest -Dbrowserstack.app=./LocalSample.apk - name: Run mvn test for testng ios run: | cd ios/testng-examples @@ -82,6 +96,20 @@ jobs: cd ios/testng-examples mvn compile mvn test -P sample-local-test -D"browserstack.app"="./LocalSample.ipa" + - name: Run Gradle test for testng ios + run: | + cd ios/testng-examples + gradle clean sampleTest + + - name: Run Gradle profile sampleTest for testng ios + run: | + cd ios/testng-examples + gradle clean sampleLocalTest + + - name: Run Gradle profile sampleLocalTest for testng ios + run: | + cd ios/testng-examples + gradle clean sample-local-test -D"browserstack.app"="./LocalSample.ipa" - if: always() uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 id: status-check-completed diff --git a/.gitignore b/.gitignore index 7f4e6b3..f5c4409 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,7 @@ local.log *.iml **/logs/* .DS_Store +build +gradle +.gradle +gradlew* diff --git a/README.md b/README.md index 3a558c2..1f1e442 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,10 @@ This repository demonstrates how to run Appium tests in [TestNG](http://testng.o - If Maven is not downloaded, download it from [here](https://maven.apache.org/download.cgi) - For installation, follow the instructions [here](https://maven.apache.org/install.html) +3. Gradle + - If Gradle is not downloaded, download it from [here](https://gradle.org/releases/) + - For installation, follow the instructions [here](https://gradle.org/install/) + ### Install the dependencies To install the dependencies for Android tests, run : @@ -43,6 +47,7 @@ Getting Started with Appium tests in TestNg on BrowserStack couldn't be easier! - Switch to one of the following directories: [Android examples](android/testng-examples) or [iOS examples](ios/testng-examples) - Run the following maven command `mvn test -P sample-test` +- Run the following gradle command `gradle clean sampleTest` ### **Use Local testing for apps that access resources hosted in development or testing environments :** @@ -52,6 +57,8 @@ Getting Started with Appium tests in TestNg on BrowserStack couldn't be easier! ``` - You can use the `LocalSample` app provided in both folder [Android examples](android/testng-examples) or [iOS examples](ios/testng-examples) 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` +-similarly for gradle you can do :- gradle clean sampleLocalTest + **Note**: If you are facing any issues, refer [Getting Help section](#Getting-Help) diff --git a/android/testng-examples/build.gradle b/android/testng-examples/build.gradle new file mode 100644 index 0000000..78a50d7 --- /dev/null +++ b/android/testng-examples/build.gradle @@ -0,0 +1,47 @@ +plugins { + id 'java' +} + +repositories { mavenCentral() } + +dependencies { + testImplementation 'org.testng:testng:7.5' + implementation 'org.seleniumhq.selenium:selenium-java:4.13.0' + implementation 'io.appium:java-client:8.6.0' + implementation 'commons-io:commons-io:2.11.0' + implementation 'com.googlecode.json-simple:json-simple:1.1.1' + implementation 'com.browserstack:browserstack-java-sdk:latest.release' +} + +group = 'com.browserstack' +version = '1.0-SNAPSHOT' +description = 'testng-browserstack' +sourceCompatibility = '1.8' + +def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' } + +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} + +tasks.withType(Test) { + systemProperties = System.properties +} + +task sampleTest(type: Test) { + useTestNG() { + dependsOn cleanTest + useDefaultListeners = true + suites "src/test/resources/com/browserstack/sample-test.testng.xml" + jvmArgs "-javaagent:${browserstackSDKArtifact.file}" + } +} + +task sampleLocalTest(type: Test) { + useTestNG() { + dependsOn cleanTest + useDefaultListeners = true + suites "src/test/resources/com/browserstack/sample-local-test.testng.xml" + jvmArgs "-javaagent:${browserstackSDKArtifact.file}" + } +} \ No newline at end of file diff --git a/android/testng-examples/settings.gradle b/android/testng-examples/settings.gradle new file mode 100644 index 0000000..460bfd2 --- /dev/null +++ b/android/testng-examples/settings.gradle @@ -0,0 +1,16 @@ +pluginManagement { + repositories { + mavenCentral() + mavenLocal() + gradlePluginPortal() + } + + resolutionStrategy { + eachPlugin { + if (requested.id.id == "com.browserstack.gradle-sdk") { + useModule("com.browserstack:gradle-sdk:1.1.2") + } + } + } +} +rootProject.name = 'testng-browserstack-android' \ No newline at end of file diff --git a/ios/testng-examples/build.gradle b/ios/testng-examples/build.gradle new file mode 100644 index 0000000..78a50d7 --- /dev/null +++ b/ios/testng-examples/build.gradle @@ -0,0 +1,47 @@ +plugins { + id 'java' +} + +repositories { mavenCentral() } + +dependencies { + testImplementation 'org.testng:testng:7.5' + implementation 'org.seleniumhq.selenium:selenium-java:4.13.0' + implementation 'io.appium:java-client:8.6.0' + implementation 'commons-io:commons-io:2.11.0' + implementation 'com.googlecode.json-simple:json-simple:1.1.1' + implementation 'com.browserstack:browserstack-java-sdk:latest.release' +} + +group = 'com.browserstack' +version = '1.0-SNAPSHOT' +description = 'testng-browserstack' +sourceCompatibility = '1.8' + +def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' } + +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} + +tasks.withType(Test) { + systemProperties = System.properties +} + +task sampleTest(type: Test) { + useTestNG() { + dependsOn cleanTest + useDefaultListeners = true + suites "src/test/resources/com/browserstack/sample-test.testng.xml" + jvmArgs "-javaagent:${browserstackSDKArtifact.file}" + } +} + +task sampleLocalTest(type: Test) { + useTestNG() { + dependsOn cleanTest + useDefaultListeners = true + suites "src/test/resources/com/browserstack/sample-local-test.testng.xml" + jvmArgs "-javaagent:${browserstackSDKArtifact.file}" + } +} \ No newline at end of file diff --git a/ios/testng-examples/settings.gradle b/ios/testng-examples/settings.gradle new file mode 100644 index 0000000..ac40cc3 --- /dev/null +++ b/ios/testng-examples/settings.gradle @@ -0,0 +1,16 @@ +pluginManagement { + repositories { + mavenCentral() + mavenLocal() + gradlePluginPortal() + } + + resolutionStrategy { + eachPlugin { + if (requested.id.id == "com.browserstack.gradle-sdk") { + useModule("com.browserstack:gradle-sdk:1.1.2") + } + } + } +} +rootProject.name = 'testng-browserstack-ios' \ No newline at end of file From 0790f6cbfbf4b6252f6d7065ce2064ca684e5323 Mon Sep 17 00:00:00 2001 From: rhisav-25 Date: Wed, 2 Apr 2025 14:36:16 +0000 Subject: [PATCH 2/2] Resolving comments and making consistent --- .github/workflows/maven-workflow-run.yml | 22 +++++---------------- README.md | 25 +++++++++++++++++++----- android/testng-examples/build.gradle | 2 +- android/testng-examples/settings.gradle | 2 +- ios/testng-examples/build.gradle | 2 +- ios/testng-examples/settings.gradle | 2 +- 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/.github/workflows/maven-workflow-run.yml b/.github/workflows/maven-workflow-run.yml index bbeffa3..19a0d5c 100644 --- a/.github/workflows/maven-workflow-run.yml +++ b/.github/workflows/maven-workflow-run.yml @@ -67,20 +67,14 @@ jobs: cd android/testng-examples mvn compile mvn test -P sample-local-test -D"browserstack.app"="./LocalSample.apk" - - name: Run Gradle test for testng Android + - name: Run Gradle sample-test for testng Android run: | cd android/testng-examples gradle clean sampleTest - - - name: Run Gradle profile sampleTest for testng Android - run: | - cd android/testng-examples - gradle clean sampleLocalTest - - - name: Run Gradle profile sampleLocalTest for testng Android + - name: Run Gradle sampleLocalTest for testng Android run: | cd android/testng-examples - gradle clean sampleLocalTest -Dbrowserstack.app=./LocalSample.apk + gradle clean sampleLocalTest -D"browserstack.app"="./LocalSample.apk" - name: Run mvn test for testng ios run: | cd ios/testng-examples @@ -96,17 +90,11 @@ jobs: cd ios/testng-examples mvn compile mvn test -P sample-local-test -D"browserstack.app"="./LocalSample.ipa" - - name: Run Gradle test for testng ios + - name: Run Gradle sample-test for testng ios run: | cd ios/testng-examples gradle clean sampleTest - - - name: Run Gradle profile sampleTest for testng ios - run: | - cd ios/testng-examples - gradle clean sampleLocalTest - - - name: Run Gradle profile sampleLocalTest for testng ios + - name: Run Gradle sampleLocalTest for testng ios run: | cd ios/testng-examples gradle clean sample-local-test -D"browserstack.app"="./LocalSample.ipa" diff --git a/README.md b/README.md index 1f1e442..7abe9a0 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,11 @@ This repository demonstrates how to run Appium tests in [TestNG](http://testng.o - For Windows, download latest java version from [here](https://java.com/en/download/) and run the installer executable - 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/) -2. Maven +2. Maven (Only required if using Maven as the build tool) - If Maven is not downloaded, download it from [here](https://maven.apache.org/download.cgi) - For installation, follow the instructions [here](https://maven.apache.org/install.html) -3. Gradle +3. Gradle (Only required if using Gradle as the build tool) - If Gradle is not downloaded, download it from [here](https://gradle.org/releases/) - For installation, follow the instructions [here](https://gradle.org/install/) @@ -46,8 +46,14 @@ Getting Started with Appium tests in TestNg on BrowserStack couldn't be easier! ### **Run Sample test :** - Switch to one of the following directories: [Android examples](android/testng-examples) or [iOS examples](ios/testng-examples) -- Run the following maven command `mvn test -P sample-test` -- Run the following gradle command `gradle clean sampleTest` +- **For Maven:** Run the following command to execute tests in the Maven environment: + ```sh + mvn test -P sample-test + ``` +- **For Gradle:** Run the following command to execute tests in the Gradle environment: + ```sh + gradle clean sampleTest + ``` ### **Use Local testing for apps that access resources hosted in development or testing environments :** @@ -55,7 +61,16 @@ Getting Started with Appium tests in TestNg on BrowserStack couldn't be easier! ``` browserstackLocal: true ``` -- You can use the `LocalSample` app provided in both folder [Android examples](android/testng-examples) or [iOS examples](ios/testng-examples) 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` +- You can use the `LocalSample` app provided in both folder [Android examples](android/testng-examples) or [iOS examples](ios/testng-examples) to run your test. Change the app parameter in the `browserstack.yml` file. + +- **For Maven:** Run the following command to execute tests in the Maven environment: + ```sh + mvn test -P sample-local-test + ``` +- **For Gradle:** Run the following command to execute tests in the Gradle environment: + ```sh + gradle clean sampleLocalTest + ``` -similarly for gradle you can do :- gradle clean sampleLocalTest diff --git a/android/testng-examples/build.gradle b/android/testng-examples/build.gradle index 78a50d7..92de6d2 100644 --- a/android/testng-examples/build.gradle +++ b/android/testng-examples/build.gradle @@ -44,4 +44,4 @@ task sampleLocalTest(type: Test) { suites "src/test/resources/com/browserstack/sample-local-test.testng.xml" jvmArgs "-javaagent:${browserstackSDKArtifact.file}" } -} \ No newline at end of file +} diff --git a/android/testng-examples/settings.gradle b/android/testng-examples/settings.gradle index 460bfd2..55607bd 100644 --- a/android/testng-examples/settings.gradle +++ b/android/testng-examples/settings.gradle @@ -13,4 +13,4 @@ pluginManagement { } } } -rootProject.name = 'testng-browserstack-android' \ No newline at end of file +rootProject.name = 'testng-browserstack-android' diff --git a/ios/testng-examples/build.gradle b/ios/testng-examples/build.gradle index 78a50d7..92de6d2 100644 --- a/ios/testng-examples/build.gradle +++ b/ios/testng-examples/build.gradle @@ -44,4 +44,4 @@ task sampleLocalTest(type: Test) { suites "src/test/resources/com/browserstack/sample-local-test.testng.xml" jvmArgs "-javaagent:${browserstackSDKArtifact.file}" } -} \ No newline at end of file +} diff --git a/ios/testng-examples/settings.gradle b/ios/testng-examples/settings.gradle index ac40cc3..e77c63f 100644 --- a/ios/testng-examples/settings.gradle +++ b/ios/testng-examples/settings.gradle @@ -13,4 +13,4 @@ pluginManagement { } } } -rootProject.name = 'testng-browserstack-ios' \ No newline at end of file +rootProject.name = 'testng-browserstack-ios'