Class PlaywrightPageRegistry

java.lang.Object
net.serenitybdd.playwright.PlaywrightPageRegistry

public class PlaywrightPageRegistry extends Object
Thread-safe registry for Playwright Page instances.

This class provides ThreadLocal storage for Playwright Page objects, enabling proper isolation in parallel test execution scenarios. Each test thread maintains its own set of registered pages.

Usage:

 // Register a page for screenshot capture
 PlaywrightPageRegistry.registerPage(page);

 // Get all registered pages for the current thread
 List<Page> pages = PlaywrightPageRegistry.getRegisteredPages();

 // Cleanup at end of test
 PlaywrightPageRegistry.clear();
 

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Clears all registered pages for the current thread.
    static List<com.microsoft.playwright.Page>
    Returns an unmodifiable list of all registered pages for the current thread.
    static boolean
    Checks if there are any registered pages for the current thread.
    static void
    registerPage(com.microsoft.playwright.Page page)
    Registers a Playwright Page instance for the current thread.
    static void
    unregisterPage(com.microsoft.playwright.Page page)
    Unregisters a Playwright Page instance from the current thread.

    Methods inherited from class java.lang.Object

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

    • PlaywrightPageRegistry

      public PlaywrightPageRegistry()
  • Method Details

    • registerPage

      public static void registerPage(com.microsoft.playwright.Page page)
      Registers a Playwright Page instance for the current thread.

      Once registered, the page will be used for automatic screenshot capture during step execution. Null values and duplicate registrations are ignored.

      Parameters:
      page - the Playwright Page to register (may be null)
    • unregisterPage

      public static void unregisterPage(com.microsoft.playwright.Page page)
      Unregisters a Playwright Page instance from the current thread.
      Parameters:
      page - the Playwright Page to unregister
    • getRegisteredPages

      public static List<com.microsoft.playwright.Page> getRegisteredPages()
      Returns an unmodifiable list of 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.

      This should be called in test cleanup to ensure proper resource management.

    • hasRegisteredPages

      public static boolean hasRegisteredPages()
      Checks if there are any registered pages for the current thread.
      Returns:
      true if at least one page is registered, false otherwise