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 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

      public static BrowseTheWebWithPlaywright as(net.serenitybdd.screenplay.Actor actor)
    • getBrowser

      public com.microsoft.playwright.Browser getBrowser()
    • getCurrentPage

      public com.microsoft.playwright.Page getCurrentPage()
    • getPhotographer

      public Photographer 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:
      asActor in interface net.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:
      tearDown in interface net.serenitybdd.screenplay.HasTeardown
    • usingTheDefaultConfiguration

      public static BrowseTheWebWithPlaywright 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 Playwright OptionsFactory.

      This allows reusing the same OptionsFactory that you use with @UsePlaywright in Screenplay tests.

    • withContextOptions

      public BrowseTheWebWithPlaywright withContextOptions(com.microsoft.playwright.Browser.NewContextOptions contextOptions)
    • withBrowserType

      public BrowseTheWebWithPlaywright withBrowserType(String browserType)
    • withHeadlessMode

      public BrowseTheWebWithPlaywright withHeadlessMode(Boolean headless)
    • withPage

      public static BrowseTheWebWithPlaywright withPage(com.microsoft.playwright.Page page)
      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

      public List<com.microsoft.playwright.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

      public void switchToPageWithTitle(String title)
      Switch to the page containing the given title.
    • switchToPageWithUrl

      public void switchToPageWithUrl(String urlSubstring)
      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

      public List<com.microsoft.playwright.options.Cookie> 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

      public void addCookies(List<com.microsoft.playwright.options.Cookie> cookies)
      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 state
      page - 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