Serenity BDD's Cucumber runner (@RunWith(CucumberWithSerenity.class)) on JUnit 6 with Playwright, running on BrowserStack with the BrowserStack Java SDK.
Use this only if your project must keep CucumberWithSerenity. For new or migrating projects use serenity-playwright-browserstack, which needs no JUnit 4 and runs scenarios in parallel.
| Part | Role |
|---|---|
| JUnit Platform 6 | Runs the JUnit 4 runner classes SampleTest and LocalTest through the vintage engine (junit-vintage-engine 6.0.3 + junit 4.13.2) |
| Serenity 5.3 | @RunWith(CucumberWithSerenity.class) runs Cucumber and builds the Serenity HTML report |
| Cucumber 7.34 | Scenarios in src/test/resources/features, configured with @CucumberOptions(features = ..., glue = ...) |
| Playwright 1.60 | Drives the browser; PlaywrightHooks opens one browser per scenario |
| BrowserStack SDK | Runs every Playwright launch() on BrowserStack, names and marks each session, and sends each scenario to Test Reporting & Analytics |
- Java 17 or newer
- Maven 3.6.3 or newer
browserstack-java-sdk1.77.0 or newer
- Clone the repo
- Replace
YOUR_USERNAMEandYOUR_ACCESS_KEYwith your BrowserStack access credentials inbrowserstack.yml, or set the environment variables (see Notes) - Install dependencies
mvn compile
- To run a sample test, run
mvn verify -P sample-test - To run local tests, run
mvn verify -P sample-local-test
Each scenario runs once per platform in browserstack.yml. On BrowserStack you get:
- Automate: one session per scenario, named
<Feature> - <Scenario>and marked passed or failed with the reason. - Test Reporting & Analytics: one test per scenario, with steps, hooks and tags, linked to its session.
The Serenity report is written to target/site/serenity/index.html.
| Setting | |
|---|---|
browserstack.yml |
framework: cucumber-junit6 (not framework: serenity, which is for Serenity with Selenium) |
| Runner | @RunWith(CucumberWithSerenity.class) + @CucumberOptions(features = ..., glue = ...) |
| JUnit | junit:junit 4.13.2 and org.junit.vintage:junit-vintage-engine 6.x, because CucumberWithSerenity is a JUnit 4 runner |
| Cucumber | io.cucumber:cucumber-junit |
| Browser | Playwright; launch() and connect() both run on BrowserStack |
| SDK | com.browserstack:browserstack-java-sdk 1.77.0+ with maven-dependency-plugin (goal properties) and the argLine -javaagent:${com.browserstack:browserstack-java-sdk:jar} on the plugin that runs the tests (see pom.xml) |
-
Parallel runs: Cucumber's JUnit 4 runner runs the scenarios of a feature one after another. The JUnit vintage engine can run features in parallel (
junit.vintage.execution.parallel.*injunit-platform.properties), not the scenarios inside one feature. -
CucumberWithSerenityis deprecated for removal since Serenity 5.0.0, and JUnit 6 deprecates the vintage engine. -
framework: cucumber-junit6runs only through the BrowserStack CLI, which the SDK downloads at startup. If the CLI can't start, the run stops before any test and prints the reason. -
You can view your test results on the BrowserStack Automate dashboard
-
You can export the environment variables for the Username and Access Key of your BrowserStack account
export BROWSERSTACK_USERNAME=<browserstack-username> && export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
