Module net.serenitybdd.playwright
Annotation Interface SerenityPlaywright
@Target(TYPE)
@Retention(RUNTIME)
@ExtendWith(net.serenitybdd.junit5.SerenityJUnit5Extension.class) @ExtendWith(SerenityPlaywrightExtension.class)
public @interface SerenityPlaywright
Convenience meta-annotation that combines Serenity and Playwright extensions.
This annotation provides a shorthand for configuring a Serenity BDD test with
Playwright support. Using this annotation is equivalent to adding both
@ExtendWith(SerenityJUnit5Extension.class) and
@ExtendWith(SerenityPlaywrightExtension.class).
Basic usage:
@SerenityPlaywright
class MyPlaywrightTest {
@Steps
MySteps steps;
private Playwright playwright;
private Browser browser;
private Page page;
@BeforeEach
void setup() {
playwright = Playwright.create();
browser = playwright.chromium().launch();
page = browser.newPage();
PlaywrightSerenity.registerPage(page);
}
@AfterEach
void teardown() {
PlaywrightSerenity.clear();
browser.close();
playwright.close();
}
@Test
void canSearchForProducts() {
steps.openHomePage();
steps.searchFor("laptop");
}
}
For use with Playwright's @UsePlaywright annotation, Playwright manages the
full browser lifecycle and Page instances are automatically registered with Serenity:
@SerenityPlaywright
@UsePlaywright(ChromeHeadlessOptions.class)
class MyPlaywrightTest {
@Steps
MySteps steps;
@BeforeEach
void setUp(Page page) {
// Page is created by Playwright and auto-registered with Serenity
}
@Test
void canSearchForProducts(Page page) {
page.navigate("https://example.com");
steps.verifyPageLoaded(page);
}
}
- See Also:
-
SerenityPlaywrightExtensionSerenityJUnit5Extension