This is a starter project for Serenity BDD with Playwright, demonstrating how to write automated browser tests with rich reporting.
- Playwright - Modern, fast, and reliable browser automation
- Serenity BDD - Rich HTML reports with screenshots at each step
- JUnit 5 - Modern test framework with excellent IDE support
- Page Objects - Clean separation of locators and test logic
- Step Libraries - Reusable test steps with automatic reporting
- Java 17 or higher
- Maven 3.8+
- An IDE (IntelliJ IDEA recommended)
src/test/java/
├── starter/
│ ├── WikipediaSearchTest.java # Test class
│ ├── pages/
│ │ └── WikipediaHomePage.java # Page Object
│ └── steps/
│ ├── NavigationSteps.java # Step library
│ └── SearchSteps.java # Step library
└── resources/
├── serenity.conf # Serenity configuration
└── logback-test.xml # Logging configuration
mvn clean verifymvn clean verify
open target/site/serenity/index.htmlEdit WikipediaSearchTest.java and change:
new BrowserType.LaunchOptions().setHeadless(false)This project follows the three-layer architecture:
Test Class (describes business scenarios)
└── Step Library (@Step methods for reporting)
└── Page Object (encapsulates locators)
Page Objects encapsulate all locator strategies and page interactions:
public class WikipediaHomePage {
private final Page page;
// Locators are private
private Locator searchBox() {
return page.getByRole(AriaRole.SEARCHBOX,
new Page.GetByRoleOptions().setName("Search Wikipedia"));
}
// Actions are public
public void searchFor(String term) {
searchBox().fill(term);
searchBox().press("Enter");
}
}Step libraries provide @Step annotations for Serenity reporting:
public class SearchSteps {
private WikipediaHomePage homePage;
@Step("Search for '{1}'")
public void searchFor(Page page, String term) {
homePage.searchFor(term);
}
}Tests use step libraries to describe business scenarios:
@ExtendWith(SerenityJUnit5Extension.class)
class WikipediaSearchTest {
@Steps SearchSteps search;
@Steps NavigationSteps navigation;
@Test
void shouldSearchForTerm() {
navigation.openWikipediaHomePage(page);
search.searchFor(page, "Playwright");
search.verifyTitleContains(page, "Playwright");
}
}After running the tests, Serenity generates rich HTML reports in target/site/serenity/:
- Test Results - Pass/fail status with screenshots
- Step Details - Each
@Stepmethod is documented - Screenshots - Captured at each step completion
- Test Timeline - Visual representation of test execution
Configure Serenity behavior in src/test/resources/serenity.conf:
serenity {
project.name = "My Project"
take.screenshots = FOR_EACH_ACTION
}| Strategy | Description |
|---|---|
FOR_EACH_ACTION |
Screenshot after every step (default) |
BEFORE_AND_AFTER_EACH_STEP |
Screenshot before and after each step |
FOR_FAILURES |
Screenshot only when a step fails |
DISABLED |
No automatic screenshots |
Playwright supports multiple browsers:
// Chromium (default)
browser = playwright.chromium().launch();
// Firefox
browser = playwright.firefox().launch();
// WebKit (Safari)
browser = playwright.webkit().launch();This project is licensed under the Apache License 2.0.