diff --git a/.github/workflows/maven-workflow-run.yml b/.github/workflows/maven-workflow-run.yml index 1682128..19a0d5c 100644 --- a/.github/workflows/maven-workflow-run.yml +++ b/.github/workflows/maven-workflow-run.yml @@ -67,6 +67,14 @@ jobs: cd android/testng-examples mvn compile mvn test -P sample-local-test -D"browserstack.app"="./LocalSample.apk" + - name: Run Gradle sample-test for testng Android + run: | + cd android/testng-examples + gradle clean sampleTest + - name: Run Gradle sampleLocalTest for testng Android + run: | + cd android/testng-examples + gradle clean sampleLocalTest -D"browserstack.app"="./LocalSample.apk" - name: Run mvn test for testng ios run: | cd ios/testng-examples @@ -82,6 +90,14 @@ jobs: cd ios/testng-examples mvn compile mvn test -P sample-local-test -D"browserstack.app"="./LocalSample.ipa" + - name: Run Gradle sample-test for testng ios + run: | + cd ios/testng-examples + gradle clean sampleTest + - name: Run Gradle 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..7abe9a0 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,14 @@ 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 (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/) + ### Install the dependencies To install the dependencies for Android tests, run : @@ -42,7 +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` +- **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 :** @@ -50,7 +61,18 @@ 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 **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..92de6d2 --- /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}" + } +} diff --git a/android/testng-examples/settings.gradle b/android/testng-examples/settings.gradle new file mode 100644 index 0000000..55607bd --- /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' diff --git a/ios/testng-examples/build.gradle b/ios/testng-examples/build.gradle new file mode 100644 index 0000000..92de6d2 --- /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}" + } +} diff --git a/ios/testng-examples/settings.gradle b/ios/testng-examples/settings.gradle new file mode 100644 index 0000000..e77c63f --- /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'