diff --git a/.github/workflows/maven-workflow-run.yml b/.github/workflows/maven-workflow-run.yml index 6eef44b..ae93601 100644 --- a/.github/workflows/maven-workflow-run.yml +++ b/.github/workflows/maven-workflow-run.yml @@ -82,6 +82,22 @@ jobs: cd ios mvn compile mvn test -P sample-test + - name: Run gradle task for android + run: | + cd android + gradle clean sampleTest + - name: Run gradle task sample-local-test for android + run: | + cd android + gradle clean sampleLocalTest -D"browserstack.app"="./LocalSample.apk" + - name: Run gradle task for ios + run: | + cd ios + gradle clean sampleTest + - name: Run gradle task sample-local-test for ios + run: | + cd ios + gradle clean sampleLocalTest -D"browserstack.app"="./LocalSample.ipa" - if: always() uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 id: status-check-completed diff --git a/.gitignore b/.gitignore index 5ffe1d3..cb4802d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,8 @@ local.log **/logs/* reports/ logs/ +bstack_* +build +.gradle +gradle +gradlew* diff --git a/README.md b/README.md index e2d488a..b0b8022 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,14 @@ This repository demonstrates how to run Appium tests in Cucumber Testng on Brows - 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 Cucumber TestNg on BrowserStack couldn't be ### **Run Sample test :** - Switch to one of the following directories: [Android examples](android) or [iOS examples](ios) -- 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,8 +61,16 @@ Getting Started with Appium tests in Cucumber TestNg on BrowserStack couldn't be ``` browserstackLocal: true ``` -- 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` - +- 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. + +- **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 + ``` **Note**: If you are facing any issues, refer [Getting Help section](#Getting-Help) diff --git a/android/build.gradle b/android/build.gradle new file mode 100644 index 0000000..456977b --- /dev/null +++ b/android/build.gradle @@ -0,0 +1,59 @@ +plugins { + id 'java' +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.seleniumhq.selenium:selenium-java:4.13.0' + testImplementation 'io.cucumber:cucumber-java:7.3.4' + testImplementation 'io.cucumber:cucumber-testng:7.3.4' + testImplementation 'io.cucumber:cucumber-core:7.3.4' + implementation "io.appium:java-client:8.6.0" + implementation "commons-io:commons-io:2.11.0" + implementation 'com.browserstack:browserstack-java-sdk:latest.release' +} + +group = 'com.browserstack' +version = '1.0-SNAPSHOT' +description = 'cucumber-java-browserstack' +sourceCompatibility = '1.8' +targetCompatibility = '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) { + systemProperty "cucumber.publish.quiet", "true" + systemProperty "cucumber.features", "src/test/resources/features/test" + systemProperties System.getProperties() + useTestNG() { + dependsOn clean + useDefaultListeners = true + suites "src/test/resources/testng.xml" + jvmArgs "-javaagent:${browserstackSDKArtifact.file}" + } + scanForTestClasses = false +} + +task sampleLocalTest(type: Test) { + systemProperty "cucumber.publish.quiet", "true" + systemProperty "cucumber.features", "src/test/resources/features/localtest" + systemProperties System.getProperties() + useTestNG() { + dependsOn clean + useDefaultListeners = true + suites "src/test/resources/testng.xml" + jvmArgs "-javaagent:${browserstackSDKArtifact.file}" + } + scanForTestClasses = false +} diff --git a/ios/build.gradle b/ios/build.gradle new file mode 100644 index 0000000..456977b --- /dev/null +++ b/ios/build.gradle @@ -0,0 +1,59 @@ +plugins { + id 'java' +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.seleniumhq.selenium:selenium-java:4.13.0' + testImplementation 'io.cucumber:cucumber-java:7.3.4' + testImplementation 'io.cucumber:cucumber-testng:7.3.4' + testImplementation 'io.cucumber:cucumber-core:7.3.4' + implementation "io.appium:java-client:8.6.0" + implementation "commons-io:commons-io:2.11.0" + implementation 'com.browserstack:browserstack-java-sdk:latest.release' +} + +group = 'com.browserstack' +version = '1.0-SNAPSHOT' +description = 'cucumber-java-browserstack' +sourceCompatibility = '1.8' +targetCompatibility = '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) { + systemProperty "cucumber.publish.quiet", "true" + systemProperty "cucumber.features", "src/test/resources/features/test" + systemProperties System.getProperties() + useTestNG() { + dependsOn clean + useDefaultListeners = true + suites "src/test/resources/testng.xml" + jvmArgs "-javaagent:${browserstackSDKArtifact.file}" + } + scanForTestClasses = false +} + +task sampleLocalTest(type: Test) { + systemProperty "cucumber.publish.quiet", "true" + systemProperty "cucumber.features", "src/test/resources/features/localtest" + systemProperties System.getProperties() + useTestNG() { + dependsOn clean + useDefaultListeners = true + suites "src/test/resources/testng.xml" + jvmArgs "-javaagent:${browserstackSDKArtifact.file}" + } + scanForTestClasses = false +}