|
| 1 | +# testng-browserstack |
| 2 | + |
| 3 | +[TestNG](http://testng.org) Integration with BrowserStack. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +## Using Maven |
| 8 | + |
| 9 | +### Run sample build |
| 10 | + |
| 11 | +- Clone the repository |
| 12 | +- Replace YOUR_USERNAME and YOUR_ACCESS_KEY with your BrowserStack access credentials in browserstack.yml. |
| 13 | +- Install dependencies `mvn compile` |
| 14 | +- To run the test suite having cross-platform with parallelization, run `mvn test -P sample-test` |
| 15 | +- To run local tests, run `mvn test -P sample-local-test` |
| 16 | + |
| 17 | +Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) |
| 18 | + |
| 19 | +### Integrate your test suite |
| 20 | + |
| 21 | +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: |
| 22 | + |
| 23 | +* Create sample browserstack.yml file with the browserstack related capabilities with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings) and place it in your root folder. |
| 24 | +* Add maven dependency of browserstack-java-sdk in your pom.xml file |
| 25 | +```sh |
| 26 | +<dependency> |
| 27 | + <groupId>com.browserstack</groupId> |
| 28 | + <artifactId>browserstack-java-sdk</artifactId> |
| 29 | + <version>LATEST</version> |
| 30 | + <scope>compile</scope> |
| 31 | +</dependency> |
| 32 | +``` |
| 33 | +* Modify your build plugin to run tests by adding argLine `-javaagent:${com.browserstack:browserstack-java-sdk:jar}` and `maven-dependency-plugin` for resolving dependencies in the profiles `sample-test` and `sample-local-test`. |
| 34 | +``` |
| 35 | + <plugin> |
| 36 | + <artifactId>maven-dependency-plugin</artifactId> |
| 37 | + <executions> |
| 38 | + <execution> |
| 39 | + <id>getClasspathFilenames</id> |
| 40 | + <goals> |
| 41 | + <goal>properties</goal> |
| 42 | + </goals> |
| 43 | + </execution> |
| 44 | + </executions> |
| 45 | + </plugin> |
| 46 | + <plugin> |
| 47 | + <groupId>org.apache.maven.plugins</groupId> |
| 48 | + <artifactId>maven-surefire-plugin</artifactId> |
| 49 | + <version>3.0.0-M5</version> |
| 50 | + <configuration> |
| 51 | + <suiteXmlFiles> |
| 52 | + <suiteXmlFile>config/sample-local-test.testng.xml</suiteXmlFile> |
| 53 | + </suiteXmlFiles> |
| 54 | + <argLine> |
| 55 | + -javaagent:${com.browserstack:browserstack-java-sdk:jar} |
| 56 | + </argLine> |
| 57 | + </configuration> |
| 58 | + </plugin> |
| 59 | +``` |
| 60 | +* Install dependencies `mvn compile` |
| 61 | + |
| 62 | +## Using Gradle |
| 63 | + |
| 64 | +### Prerequisites |
| 65 | +- If using Gradle, Java v9+ is required. |
| 66 | + |
| 67 | +### Run sample build |
| 68 | + |
| 69 | +- Clone the repository |
| 70 | +- Install dependencies `gradle build` |
| 71 | +- To run the test suite having cross-platform with parallelization, run `gradle sampleTest` |
| 72 | +- To run local tests, run `gradle sampleLocalTest` |
| 73 | + |
| 74 | +Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) |
| 75 | + |
| 76 | +### Integrate your test suite |
| 77 | + |
| 78 | +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: |
| 79 | + |
| 80 | +* Following are the changes required in `gradle.build` - |
| 81 | + * Add `compileOnly 'com.browserstack:browserstack-java-sdk:latest.release'` in dependencies |
| 82 | + * Fetch Artifact Information and add `jvmArgs` property in tasks *SampleTest* and *SampleLocalTest* : |
| 83 | + ``` |
| 84 | + def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' } |
| 85 | + |
| 86 | + task sampleTest(type: Test) { |
| 87 | + useTestNG() { |
| 88 | + dependsOn cleanTest |
| 89 | + useDefaultListeners = true |
| 90 | + suites "config/sample-test.testng.xml" |
| 91 | + jvmArgs "-javaagent:${browserstackSDKArtifact.file}" |
| 92 | + } |
| 93 | + } |
| 94 | + ``` |
| 95 | + |
| 96 | +* Install dependencies `gradle build` |
| 97 | + |
| 98 | + |
| 99 | +## Notes |
| 100 | +* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate) |
0 commit comments