Class BrowseTheWebWithPlaywright
java.lang.Object
net.serenitybdd.screenplay.playwright.abilities.BrowseTheWebWithPlaywright
- All Implemented Interfaces:
net.serenitybdd.screenplay.Ability,net.serenitybdd.screenplay.HasTeardown,net.serenitybdd.screenplay.RefersToActor
public class BrowseTheWebWithPlaywright
extends Object
implements net.serenitybdd.screenplay.Ability, net.serenitybdd.screenplay.RefersToActor, net.serenitybdd.screenplay.HasTeardown
A Screenplay ability that wraps the Playwright Browser object.
The browser type is read from playwright.browsertype and headless mode from
playwright.headless. For additional launch options, use withOptions(BrowserType.LaunchOptions).
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBrowseTheWebWithPlaywright(net.thucydides.model.util.EnvironmentVariables environmentVariables) protectedBrowseTheWebWithPlaywright(net.thucydides.model.util.EnvironmentVariables environmentVariables, com.microsoft.playwright.BrowserType.LaunchOptions launchOptions) protectedBrowseTheWebWithPlaywright(net.thucydides.model.util.EnvironmentVariables environmentVariables, com.microsoft.playwright.BrowserType.LaunchOptions launchOptions, com.microsoft.playwright.Browser.NewContextOptions contextOptions, String browserType) protectedBrowseTheWebWithPlaywright(net.thucydides.model.util.EnvironmentVariables environmentVariables, com.microsoft.playwright.BrowserType.LaunchOptions launchOptions, String browserType) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCookie(com.microsoft.playwright.options.Cookie cookie) Add a cookie to the current context.voidaddCookies(List<com.microsoft.playwright.options.Cookie> cookies) Add multiple cookies to the current context.static BrowseTheWebWithPlaywrightas(net.serenitybdd.screenplay.Actor actor) <T extends net.serenitybdd.screenplay.Ability>
TasActor(net.serenitybdd.screenplay.Actor actor) voidbeginPerformance(net.serenitybdd.screenplay.events.ActorBeginsPerformanceEvent performanceEvent) voidClear all cookies from the current context.voidClose the current page and switch to the previous one if available.voidendPerformance(net.serenitybdd.screenplay.events.ActorEndsPerformanceEvent performanceEvent) List<com.microsoft.playwright.Page>Get all pages (tabs) in the current browser context.com.microsoft.playwright.APIRequestContextGet the APIRequestContext for making API calls within the browser session.com.microsoft.playwright.BrowserList<com.microsoft.playwright.options.Cookie>Get all cookies from the current context.com.microsoft.playwright.Pagevoidcom.microsoft.playwright.PageOpen a new page (tab) in the current context.voidperform(net.serenitybdd.screenplay.events.ActorPerforms performAction) voidprepareQuestion(net.serenitybdd.screenplay.events.ActorAsksQuestion questionEvent) voidsetRestoredContext(com.microsoft.playwright.BrowserContext context, com.microsoft.playwright.Page page) Set a restored browser context and page.voidswitchToPage(int index) Switch to a different page by index.voidswitchToPageWithTitle(String title) Switch to the page containing the given title.voidswitchToPageWithUrl(String urlSubstring) Switch to the page with the given URL substring.net.thucydides.model.screenshots.ScreenshotAndHtmlSourcevoidtearDown()Clean up Playwright resources.voidtestFinishes(net.thucydides.core.events.TestLifecycleEvents.TestFinished testFinished) Shut down the Playwright instance and browser cleanly at the end of a Screenplay test.static BrowseTheWebWithPlaywrightCreate a new Playwright ability using default configuration values.withBrowserType(String browserType) withContextOptions(com.microsoft.playwright.Browser.NewContextOptions contextOptions) withHeadlessMode(Boolean headless) static BrowseTheWebWithPlaywrightwithOptions(com.microsoft.playwright.BrowserType.LaunchOptions options) static BrowseTheWebWithPlaywrightwithOptions(com.microsoft.playwright.junit.OptionsFactory optionsFactory) Create a new Playwright ability using configuration from a PlaywrightOptionsFactory.static BrowseTheWebWithPlaywrightwithPage(com.microsoft.playwright.Page page) Create a lightweight BrowseTheWebWithPlaywright ability that wraps an externally-provided Page.
-
Constructor Details
-
BrowseTheWebWithPlaywright
protected BrowseTheWebWithPlaywright(net.thucydides.model.util.EnvironmentVariables environmentVariables) -
BrowseTheWebWithPlaywright
protected BrowseTheWebWithPlaywright(net.thucydides.model.util.EnvironmentVariables environmentVariables, com.microsoft.playwright.BrowserType.LaunchOptions launchOptions) -
BrowseTheWebWithPlaywright
protected BrowseTheWebWithPlaywright(net.thucydides.model.util.EnvironmentVariables environmentVariables, com.microsoft.playwright.BrowserType.LaunchOptions launchOptions, String browserType) -
BrowseTheWebWithPlaywright
protected BrowseTheWebWithPlaywright(net.thucydides.model.util.EnvironmentVariables environmentVariables, com.microsoft.playwright.BrowserType.LaunchOptions launchOptions, com.microsoft.playwright.Browser.NewContextOptions contextOptions, String browserType)
-
-
Method Details
-
as
-
getBrowser
public com.microsoft.playwright.Browser getBrowser() -
getCurrentPage
public com.microsoft.playwright.Page getCurrentPage() -
getPhotographer
-
takeScreenShot
public net.thucydides.model.screenshots.ScreenshotAndHtmlSource takeScreenShot() -
notifyScreenChange
public void notifyScreenChange() -
asActor
public <T extends net.serenitybdd.screenplay.Ability> T asActor(net.serenitybdd.screenplay.Actor actor) - Specified by:
asActorin interfacenet.serenitybdd.screenplay.RefersToActor
-
beginPerformance
public void beginPerformance(net.serenitybdd.screenplay.events.ActorBeginsPerformanceEvent performanceEvent) -
endPerformance
public void endPerformance(net.serenitybdd.screenplay.events.ActorEndsPerformanceEvent performanceEvent) -
perform
public void perform(net.serenitybdd.screenplay.events.ActorPerforms performAction) -
prepareQuestion
public void prepareQuestion(net.serenitybdd.screenplay.events.ActorAsksQuestion questionEvent) -
testFinishes
public void testFinishes(net.thucydides.core.events.TestLifecycleEvents.TestFinished testFinished) Shut down the Playwright instance and browser cleanly at the end of a Screenplay test. -
tearDown
public void tearDown()Clean up Playwright resources. This method is called by the Screenplay framework when actor.wrapUp() is invoked, and also automatically at test completion.- Specified by:
tearDownin interfacenet.serenitybdd.screenplay.HasTeardown
-
usingTheDefaultConfiguration
Create a new Playwright ability using default configuration values. -
withOptions
public static BrowseTheWebWithPlaywright withOptions(com.microsoft.playwright.BrowserType.LaunchOptions options) -
withOptions
public static BrowseTheWebWithPlaywright withOptions(com.microsoft.playwright.junit.OptionsFactory optionsFactory) Create a new Playwright ability using configuration from a PlaywrightOptionsFactory.This allows reusing the same
OptionsFactorythat you use with@UsePlaywrightin Screenplay tests. -
withContextOptions
public BrowseTheWebWithPlaywright withContextOptions(com.microsoft.playwright.Browser.NewContextOptions contextOptions) -
withBrowserType
-
withHeadlessMode
-
withPage
Create a lightweight BrowseTheWebWithPlaywright ability that wraps an externally-provided Page.Use this when Playwright manages its own lifecycle externally (e.g. via
@UsePlaywright) and you want Screenplay actors to reuse the existing browser session instead of creating a new one.The returned ability will NOT close the Page, BrowserContext, Browser, or Playwright instance on teardown, since those are owned by the external provider.
- Parameters:
page- the externally-managed Playwright Page to wrap- Returns:
- a BrowseTheWebWithPlaywright ability backed by the given page
-
getAllPages
Get all pages (tabs) in the current browser context. -
switchToPage
public void switchToPage(int index) Switch to a different page by index. Note: All pages in the context remain registered with PlaywrightSerenity since they are all valid pages that can take screenshots. -
switchToPageWithTitle
Switch to the page containing the given title. -
switchToPageWithUrl
Switch to the page with the given URL substring. -
openNewPage
public com.microsoft.playwright.Page openNewPage()Open a new page (tab) in the current context. -
closeCurrentPage
public void closeCurrentPage()Close the current page and switch to the previous one if available. -
getCookies
Get all cookies from the current context. -
addCookie
public void addCookie(com.microsoft.playwright.options.Cookie cookie) Add a cookie to the current context. -
addCookies
Add multiple cookies to the current context. -
clearCookies
public void clearCookies()Clear all cookies from the current context. -
setRestoredContext
public void setRestoredContext(com.microsoft.playwright.BrowserContext context, com.microsoft.playwright.Page page) Set a restored browser context and page. Used internally by RestoreSessionState to apply saved session state.- Parameters:
context- The new browser context with restored statepage- The new page in the restored context
-
getAPIRequestContext
public com.microsoft.playwright.APIRequestContext getAPIRequestContext()Get the APIRequestContext for making API calls within the browser session. This allows API testing with the same cookies and authentication as the browser.- Returns:
- The APIRequestContext for the current browser context
-