Class PlaywrightCast
java.lang.Object
net.serenitybdd.screenplay.actors.Cast
net.serenitybdd.screenplay.playwright.actors.PlaywrightCast
public class PlaywrightCast
extends net.serenitybdd.screenplay.actors.Cast
A Cast implementation that automatically provides actors with the ability to browse the web using Playwright.
This class simplifies Screenplay tests by managing actor lifecycle and Playwright browser instances. Actors created through this Cast will automatically have the BrowseTheWebWithPlaywright ability.
Usage with JUnit 5:
@BeforeEach
void setupStage() {
OnStage.setTheStage(new PlaywrightCast());
}
@AfterEach
void teardownStage() {
OnStage.drawTheCurtain();
}
@Test
void shouldSearchForProducts() {
Actor customer = OnStage.theActorCalled("Customer");
customer.attemptsTo(
Open.url("https://example.com"),
SearchFor.product("Widget")
);
}
Usage with Cucumber:
Create a hooks class in your step definitions package:
public class PlaywrightHooks {
@Before(order = 0)
public void setTheStage(Scenario scenario) {
OnStage.setTheStage(new PlaywrightCast());
}
@ParameterType(".*")
public Actor actor(String actorName) {
return OnStage.theActorCalled(actorName);
}
}
The cleanup is handled automatically by Serenity's StageDirector when you include
net.serenitybdd.cucumber.actors in your Cucumber glue path:
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "your.steps,net.serenitybdd.cucumber.actors")
The OnStage.drawTheCurtain() call will automatically clean up all browser resources.
-
Constructor Summary
ConstructorsConstructorDescriptionPlaywrightCast(Consumer<net.serenitybdd.screenplay.Actor>... providers) PlaywrightCast(net.serenitybdd.screenplay.Ability[] abilities) -
Method Summary
Modifier and TypeMethodDescriptionnet.serenitybdd.screenplay.ActoractorNamed(String actorName, net.serenitybdd.screenplay.Ability... abilities) static PlaywrightCastwhereEveryoneCan(Consumer<net.serenitybdd.screenplay.Actor>... abilityProviders) Create a PlaywrightCast where each actor is configured using the provided function.static PlaywrightCastwhereEveryoneCan(net.serenitybdd.screenplay.Ability... abilities) Create a PlaywrightCast where all actors have the specified abilities in addition to BrowseTheWebWithPlaywright.withBrowserType(String browserType) Set the browser type (chromium, firefox, or webkit).withContextOptions(com.microsoft.playwright.Browser.NewContextOptions options) Configure context options for browser contexts.withHeadlessMode(boolean headless) Set headless mode for the browser.withLaunchOptions(com.microsoft.playwright.BrowserType.LaunchOptions options) Configure launch options for the Playwright browser.withOptions(com.microsoft.playwright.junit.OptionsFactory optionsFactory) Configure the cast using a PlaywrightOptionsFactory.Methods inherited from class net.serenitybdd.screenplay.actors.Cast
assignGeneralAbilitiesTo, dismissAll, getActors, ofStandardActors
-
Constructor Details
-
PlaywrightCast
public PlaywrightCast() -
PlaywrightCast
public PlaywrightCast(net.serenitybdd.screenplay.Ability[] abilities) -
PlaywrightCast
-
-
Method Details
-
whereEveryoneCan
Create a PlaywrightCast where all actors have the specified abilities in addition to BrowseTheWebWithPlaywright. -
whereEveryoneCan
@SafeVarargs public static PlaywrightCast whereEveryoneCan(Consumer<net.serenitybdd.screenplay.Actor>... abilityProviders) Create a PlaywrightCast where each actor is configured using the provided function. -
withLaunchOptions
Configure launch options for the Playwright browser. -
withContextOptions
public PlaywrightCast withContextOptions(com.microsoft.playwright.Browser.NewContextOptions options) Configure context options for browser contexts. -
withBrowserType
Set the browser type (chromium, firefox, or webkit). -
withOptions
Configure the cast using a PlaywrightOptionsFactory.This allows reusing the same
OptionsFactorythat you use with@UsePlaywrightwhen setting up a Screenplay stage. -
withHeadlessMode
Set headless mode for the browser. -
actorNamed
public net.serenitybdd.screenplay.Actor actorNamed(String actorName, net.serenitybdd.screenplay.Ability... abilities) - Overrides:
actorNamedin classnet.serenitybdd.screenplay.actors.Cast
-