|
1 | 1 | # Cucumber Java Browserstack |
2 | | -<img src="src/test/resources/img/browserstack.png" width="60" height="60" ><img src="src/test/resources/img/cucumber.png" width="60" height="60" > |
| 2 | + |
3 | 3 |
|
4 | 4 | [Cucumber JVM](https://cucumber.io/docs/reference/jvm) Integration with BrowserStack. |
5 | 5 |
|
6 | | -## Setup |
7 | | -* Clone the repo |
8 | | -* Install dependencies `mvn install` |
9 | | -* Set environment variables with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings). |
10 | | -* Update `*.conf.js` files inside the `src/test/resources/conf/` directory to update desired capabilities. |
| 6 | +## Using Maven |
11 | 7 |
|
12 | | -## Running your tests |
13 | | -* To run tests, run `mvn test -P parallel` |
14 | | -* To run local tests, run `mvn test -P local` |
| 8 | +### Run sample build |
15 | 9 |
|
| 10 | +- Clone the repository |
| 11 | +- Replace YOUR_USERNAME and YOUR_ACCESS_KEY with your BrowserStack access credentials in browserstack.yml. |
| 12 | +- Install dependencies `mvn compile` |
| 13 | +- To run the test suite having cross-platform with parallelization, run `mvn test -P sample-test` |
| 14 | +- To run local tests, run `mvn test -P sample-local-test` |
| 15 | +- To view Allure Reports, run `allure serve target/allure-results` |
16 | 16 |
|
| 17 | +Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) |
17 | 18 |
|
18 | | -## Notes |
19 | | -* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate) |
20 | | -* To test on a different set of browsers, check out our [platform configurator](https://www.browserstack.com/automate/java#setting-os-and-browser) |
21 | | -* You can export the environment variables for the Username and Access Key of your BrowserStack account. |
| 19 | +### Integrate your test suite |
| 20 | + |
| 21 | +* Install dependencies `mvn compile` |
| 22 | +* 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. |
| 23 | +* Add maven dependency of browserstack-java-sdk in your pom.xml file |
| 24 | +```sh |
| 25 | +<dependency> |
| 26 | + <groupId>com.browserstack</groupId> |
| 27 | + <artifactId>browserstack-java-sdk</artifactId> |
| 28 | + <version>LATEST</version> |
| 29 | + <scope>compile</scope> |
| 30 | +</dependency> |
| 31 | +``` |
| 32 | +* 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`. |
| 33 | +``` |
| 34 | + <plugin> |
| 35 | + <artifactId>maven-dependency-plugin</artifactId> |
| 36 | + <executions> |
| 37 | + <execution> |
| 38 | + <id>getClasspathFilenames</id> |
| 39 | + <goals> |
| 40 | + <goal>properties</goal> |
| 41 | + </goals> |
| 42 | + </execution> |
| 43 | + </executions> |
| 44 | + </plugin> |
| 45 | + <plugin> |
| 46 | + <groupId>org.apache.maven.plugins</groupId> |
| 47 | + <artifactId>maven-surefire-plugin</artifactId> |
| 48 | + <version>3.0.0-M5</version> |
| 49 | + <configuration> |
| 50 | + <suiteXmlFiles> |
| 51 | + <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile> |
| 52 | + </suiteXmlFiles> |
| 53 | + <argLine> |
| 54 | + -javaagent:${com.browserstack:browserstack-java-sdk:jar} |
| 55 | + </argLine> |
| 56 | + </configuration> |
| 57 | + </plugin> |
| 58 | +``` |
| 59 | + |
| 60 | +### Migrate from Vanilla Cucumber to use Testng Runner |
| 61 | +* If you are using Vanilla Cucumber CLI, you can migrate to use TestNG Runner with BrowserStack using the below command : |
| 62 | +``` |
| 63 | +mvn archetype:generate -DarchetypeGroupId=com.browserstack -DarchetypeArtifactId=cucumber-testng-archetype -DarchetypeVersion=1.0 -DgroupId=com.browserstack -DartifactId=cucumber-testng-archetype -Dversion=1.0 -DinteractiveMode=false |
| 64 | +``` |
| 65 | +* Run your tests using `mvn test` |
| 66 | +* To use specific `@CucumberOptions` in generated class `BrowserStackCucumberTestNgRunner`, refer - https://javadoc.io/static/io.cucumber/cucumber-testng/5.0.0-RC2/io/cucumber/testng/CucumberOptions.html |
| 67 | + |
| 68 | +## Using Gradle |
| 69 | + |
| 70 | +### Run sample build |
22 | 71 |
|
| 72 | +- Clone the repository |
| 73 | +- Install dependencies `gradle build` |
| 74 | +- To run the test suite having cross-platform with parallelization, run `gradle sampleTest` |
| 75 | +- To run local tests, run `gradle sampleLocalTest` |
| 76 | + |
| 77 | +Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) |
| 78 | + |
| 79 | +### Integrate your test suite |
| 80 | + |
| 81 | +* Install dependencies `gradle build` |
| 82 | +* Following are the changes required in `gradle.build` - |
| 83 | + * Add `compileOnly 'com.browserstack:browserstack-java-sdk:latest.release'` in dependencies |
| 84 | + * Fetch Artifact Information and add `jvmArgs` property in tasks *SampleTest* and *SampleLocalTest* : |
23 | 85 | ``` |
24 | | - export BROWSERSTACK_USERNAME=<browserstack-username> && |
25 | | - export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key> |
| 86 | + def browserstackSDKArtifact = configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.find { it.name == 'browserstack-java-sdk' } |
| 87 | + |
| 88 | + task sampleTest(type: Test) { |
| 89 | + useTestNG() { |
| 90 | + dependsOn cleanTest |
| 91 | + useDefaultListeners = true |
| 92 | + suites "config/sample-test.testng.xml" |
| 93 | + jvmArgs "-javaagent:${browserstackSDKArtifact.file}" |
| 94 | + } |
| 95 | + } |
26 | 96 | ``` |
27 | 97 |
|
28 | | -## Addtional Resources |
29 | | -* [Documentation for writing Automate test scripts in Java](https://www.browserstack.com/automate/java) |
30 | | -* [Customizing your tests on BrowserStack](https://www.browserstack.com/automate/capabilities) |
31 | | -* [Browsers & mobile devices for selenium testing on BrowserStack](https://www.browserstack.com/list-of-browsers-and-platforms?product=automate) |
32 | | -* [Using REST API to access information about your tests via the command-line interface](https://www.browserstack.com/automate/rest-api) |
| 98 | +## Notes |
| 99 | +* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate) |
0 commit comments