diff --git a/.github/workflows/maven-workflow-run.yml b/.github/workflows/maven-workflow-run.yml index d222ea6..9dad777 100644 --- a/.github/workflows/maven-workflow-run.yml +++ b/.github/workflows/maven-workflow-run.yml @@ -19,6 +19,9 @@ jobs: matrix: java: [ '8', '11', '17' ] os: [ 'macos-latest', 'windows-latest', 'ubuntu-latest' ] + exclude: + - java: '8' + os: 'macos-latest' name: Selenide Repo ${{ matrix.Java }} - ${{ matrix.os }} Sample env: BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} @@ -64,6 +67,12 @@ jobs: run: | mvn compile mvn test -P sample-test + - name: Run gradle task sampleTest + run: | + gradle clean sampleTest + - name: Run gradle task sampleLocalTest + run: | + gradle clean sampleLocalTest - if: always() uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 id: status-check-completed diff --git a/.gitignore b/.gitignore index 5c4c481..3f71237 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,9 @@ hs_err_pid* *.iws /target/ build +.gradle +gradle +gradlew* .DS_Store local.log diff --git a/README.md b/README.md index af21621..b88ab8b 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,15 @@ -## Setup +## Using Maven + +### Setup * Clone the repo * Install dependencies `mvn compile` * Update `browserstack.yml` files at the root directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings) -## Running your tests +### Running your tests - To run a parallel tests, run `mvn test -P sample-test` - To run local tests, run `mvn test -P sample-local-test` @@ -20,6 +22,46 @@ Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) +## Using Gradle + +### Prerequisites +- If using Gradle, Java v9+ is required. + +### Setup + +- Clone the repository +- Install dependencies `gradle build` +- Update `browserstack.yml` files at the root directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings) + +### Run sample build + +- To run the test suite having cross-platform with parallelization, run `gradle sampleTest` +- To run local tests, run `gradle sampleLocalTest` + +Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) + +### Integrate your test suite + +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: + +* Following are the changes required in `build.gradle` - + * Add `implementation 'com.browserstack:browserstack-java-sdk:latest.release'` in dependencies + * Fetch Artifact Information and add `jvmArgs` property in tasks *SampleTest* and *SampleLocalTest* : + ``` + def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' } + + task sampleTest(type: Test) { + useTestNG() { + dependsOn cleanTest + useDefaultListeners = true + suites "config/sample.testng.xml" + jvmArgs "-javaagent:${browserstackSDKArtifact.file}" + } + } + ``` + +* Install dependencies `gradle build` + ## Notes * You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate) * To test on a different set of browsers, check out our [platform configurator](https://www.browserstack.com/automate/java#setting-os-and-browser) diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..0f665c9 --- /dev/null +++ b/build.gradle @@ -0,0 +1,45 @@ +plugins { + id 'java' +} + +repositories { mavenCentral() } + +dependencies { + implementation 'org.testng:testng:7.4.0' + implementation 'org.seleniumhq.selenium:selenium-java:4.1.0' + implementation 'com.codeborne:selenide:6.17.0' + implementation 'org.yaml:snakeyaml:2.2' + implementation 'com.browserstack:browserstack-java-sdk:latest.release' +} + +group = 'com.browserstack' +version = '1.0-SNAPSHOT' +description = 'selenide-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 + jvmArgs += "-javaagent:${browserstackSDKArtifact.file}" +} + +task sampleTest(type: Test) { + useTestNG() { + dependsOn cleanTest + useDefaultListeners = true + suites "config/sample.testng.xml" + } +} + +task sampleLocalTest(type: Test) { + useTestNG() { + dependsOn cleanTest + useDefaultListeners = true + suites "config/local.testng.xml" + } +}