|
2 | 2 |
|
3 | 3 | [TestNG](http://testng.org) Integration with BrowserStack.
|
4 | 4 |
|
5 |
| -Master branch contains **Selenium 3** samples, for **Selenium 4 - W3C protocol** please checkout [selenium-4](https://github.com/browserstack/testng-browserstack/tree/selenium-4) branch |
6 |
| - |
7 | 5 | 
|
8 | 6 |
|
9 | 7 | ## Using Maven
|
10 | 8 |
|
11 |
| -### Setup |
12 |
| - |
13 |
| -* Clone the repo |
| 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 | +``` |
14 | 60 | * Install dependencies `mvn compile`
|
15 |
| -* Update `*.conf.json` files inside the `src/test/resources/conf` directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings) |
16 | 61 |
|
17 |
| -### Running your tests |
| 62 | +## Using Gradle |
18 | 63 |
|
19 |
| -- To run a single test, run `mvn test -P single` |
20 |
| -- To run local tests, run `mvn test -P local` |
21 |
| -- To run parallel tests, run `mvn test -P parallel` |
22 |
| -- To run the test suite, run `mvn test -P suite` |
| 64 | +### Run sample build |
23 | 65 |
|
24 |
| - Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) |
25 |
| - |
26 |
| - |
27 |
| - ## Using Gradle |
28 |
| - |
29 |
| - ### Setup |
| 66 | +- Clone the repository |
| 67 | +- Install dependencies `gradle build` |
| 68 | +- To run the test suite having cross-platform with parallelization, run `gradle sampleTest` |
| 69 | +- To run local tests, run `gradle sampleLocalTest` |
30 | 70 |
|
31 |
| -* Clone the repo |
32 |
| -* Install dependencies `gradle build` |
33 |
| -* Update `*.conf.json` files inside the `src/test/resources/conf` directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings) |
| 71 | +Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) |
34 | 72 |
|
35 |
| -### Running your tests |
| 73 | +### Integrate your test suite |
36 | 74 |
|
37 |
| -- To run a single test, run `gradle singleTest` |
38 |
| -- To run local tests, run `gradle localTest` |
39 |
| -- To run parallel tests, run `gradle parallelTest` |
40 |
| -- To run the test suite, run `gradle suiteTest` |
| 75 | +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: |
41 | 76 |
|
42 |
| - Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) |
| 77 | +* Following are the changes required in `gradle.build` - |
| 78 | + * Add `compileOnly 'com.browserstack:browserstack-java-sdk:latest.release'` in dependencies |
| 79 | + * Fetch Artifact Information and add `jvmArgs` property in tasks *SampleTest* and *SampleLocalTest* : |
| 80 | + ``` |
| 81 | + def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' } |
| 82 | + |
| 83 | + task sampleTest(type: Test) { |
| 84 | + useTestNG() { |
| 85 | + dependsOn cleanTest |
| 86 | + useDefaultListeners = true |
| 87 | + suites "config/sample-test.testng.xml" |
| 88 | + jvmArgs "-javaagent:${browserstackSDKArtifact.file}" |
| 89 | + } |
| 90 | + } |
| 91 | + ``` |
| 92 | + |
| 93 | +* Install dependencies `gradle build` |
43 | 94 |
|
44 | 95 |
|
45 | 96 | ## Notes
|
46 | 97 | * You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate)
|
47 |
| -* To test on a different set of browsers, check out our [platform configurator](https://www.browserstack.com/automate/java#setting-os-and-browser) |
48 |
| -* You can export the environment variables for the Username and Access Key of your BrowserStack account |
49 |
| - |
50 |
| - ``` |
51 |
| - export BROWSERSTACK_USERNAME=<browserstack-username> && |
52 |
| - export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key> |
53 |
| - ``` |
54 |
| - |
55 |
| -## Additional Resources |
56 |
| -* [Documentation for writing Automate test scripts in Java](https://www.browserstack.com/automate/java) |
57 |
| -* [Customizing your tests on BrowserStack](https://www.browserstack.com/automate/capabilities) |
58 |
| -* [Browsers & mobile devices for selenium testing on BrowserStack](https://www.browserstack.com/list-of-browsers-and-platforms?product=automate) |
59 |
| -* [Using REST API to access information about your tests via the command-line interface](https://www.browserstack.com/automate/rest-api) |
|
0 commit comments