Class PlaywrightSerenity

java.lang.Object
net.serenitybdd.playwright.PlaywrightSerenity

public class PlaywrightSerenity extends Object
Main entry point for Playwright integration with Serenity BDD.

This class provides a simple API for registering Playwright Page instances with Serenity, enabling automatic screenshot capture during step execution.

Basic usage:

 // In your test setup
 Page page = browser.newPage();
 PlaywrightSerenity.registerPage(page);

 // Run your tests with @Step annotated methods
 // Screenshots will be automatically captured

 // In your test cleanup
 PlaywrightSerenity.unregisterPage(page);
 

See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Clears all registered pages for the current thread.
    static com.microsoft.playwright.Page
    Returns the most recently registered Page for the current thread.
    static List<com.microsoft.playwright.Page>
    Returns all registered pages for the current thread.
    static void
    registerPage(com.microsoft.playwright.Page page)
    Registers a Playwright Page instance for screenshot capture.
    static void
    Manually triggers screenshot capture for all registered pages.
    static void
    unregisterPage(com.microsoft.playwright.Page page)
    Unregisters a Playwright Page instance.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PlaywrightSerenity

      public PlaywrightSerenity()
  • Method Details

    • registerPage

      public static void registerPage(com.microsoft.playwright.Page page)
      Registers a Playwright Page instance for screenshot capture.

      Once registered, screenshots will be automatically captured for this page at the completion of each @Step annotated method.

      Parameters:
      page - the Playwright Page to register
    • unregisterPage

      public static void unregisterPage(com.microsoft.playwright.Page page)
      Unregisters a Playwright Page instance.

      Call this in your test cleanup to stop screenshot capture for this page.

      Parameters:
      page - the Playwright Page to unregister
    • getCurrentPage

      public static com.microsoft.playwright.Page getCurrentPage()
      Returns the most recently registered Page for the current thread.

      This is useful in step library methods that need access to the Page without having it passed as a parameter.

      Returns:
      the most recently registered Page, or null if none registered
    • getRegisteredPages

      public static List<com.microsoft.playwright.Page> getRegisteredPages()
      Returns all registered pages for the current thread.
      Returns:
      unmodifiable list of registered Page instances
    • clear

      public static void clear()
      Clears all registered pages for the current thread.

      Call this in your test cleanup to ensure proper resource management.

    • takeScreenshot

      public static void takeScreenshot()
      Manually triggers screenshot capture for all registered pages.

      Screenshots are normally captured automatically at step boundaries. This method allows explicit capture at any point in a test.