Class PlaywrightOptionsResolver

java.lang.Object
net.serenitybdd.playwright.PlaywrightOptionsResolver

public class PlaywrightOptionsResolver extends Object
Stateless utility that translates a Playwright Options object into the concrete Playwright/Browser/Context instances.

Both PlaywrightBrowserManager and the Screenplay BrowseTheWebWithPlaywright ability delegate here so the resolution logic lives in one place.

Mutation note: resolveLaunchOptions(com.microsoft.playwright.junit.Options) and resolveContextOptions(com.microsoft.playwright.junit.Options) apply shorthand fields (headless, channel, baseUrl, ignoreHTTPSErrors) directly onto the nested objects inside Options. This matches how Playwright's own JUnit extension behaves. Callers that need isolation should obtain a fresh Options instance per invocation (e.g. via OptionsFactory.getOptions()).

  • Method Summary

    Modifier and Type
    Method
    Description
    static com.microsoft.playwright.Playwright
    createPlaywright(com.microsoft.playwright.junit.Options options)
    Create a Playwright instance, applying playwrightCreateOptions and testIdAttribute from Options.
    static com.microsoft.playwright.Browser
    launchOrConnect(com.microsoft.playwright.junit.Options options, com.microsoft.playwright.BrowserType browserType, com.microsoft.playwright.BrowserType.LaunchOptions launchOptions)
    Launch a browser or connect to a remote endpoint based on the Options.
    static String
    resolveBrowserType(com.microsoft.playwright.junit.Options options, String fallback)
    Resolve the browser type name from Options, falling back to the given default.
    static com.microsoft.playwright.Browser.NewContextOptions
    resolveContextOptions(com.microsoft.playwright.junit.Options options)
    Build the effective Browser.NewContextOptions from the given Options.
    static com.microsoft.playwright.BrowserType.LaunchOptions
    resolveLaunchOptions(com.microsoft.playwright.junit.Options options)
    Build the effective BrowserType.LaunchOptions from the given Options.

    Methods inherited from class java.lang.Object

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

    • resolveBrowserType

      public static String resolveBrowserType(com.microsoft.playwright.junit.Options options, String fallback)
      Resolve the browser type name from Options, falling back to the given default.
      Parameters:
      options - the Playwright Options (may be null)
      fallback - the default browser type when Options doesn't specify one
      Returns:
      a non-null browser type name
    • resolveLaunchOptions

      public static com.microsoft.playwright.BrowserType.LaunchOptions resolveLaunchOptions(com.microsoft.playwright.junit.Options options)
      Build the effective BrowserType.LaunchOptions from the given Options.

      When options.launchOptions is present it is used as the base; otherwise a fresh instance is created. Shorthand fields headless and channel are then applied on top.

      Parameters:
      options - the Playwright Options (must not be null)
      Returns:
      resolved launch options (never null)
    • resolveContextOptions

      public static com.microsoft.playwright.Browser.NewContextOptions resolveContextOptions(com.microsoft.playwright.junit.Options options)
      Build the effective Browser.NewContextOptions from the given Options.

      When options.contextOptions is present it is used as the base. Shorthand fields baseUrl and ignoreHTTPSErrors are applied on top when set. Returns null when neither the base nor any shorthand is specified.

      Parameters:
      options - the Playwright Options (must not be null)
      Returns:
      resolved context options, or null if nothing is configured
    • createPlaywright

      public static com.microsoft.playwright.Playwright createPlaywright(com.microsoft.playwright.junit.Options options)
      Create a Playwright instance, applying playwrightCreateOptions and testIdAttribute from Options.
      Parameters:
      options - the Playwright Options (must not be null)
      Returns:
      a new Playwright instance
    • launchOrConnect

      public static com.microsoft.playwright.Browser launchOrConnect(com.microsoft.playwright.junit.Options options, com.microsoft.playwright.BrowserType browserType, com.microsoft.playwright.BrowserType.LaunchOptions launchOptions)
      Launch a browser or connect to a remote endpoint based on the Options.

      When options.wsEndpoint is set and non-empty, a WebSocket connection is established using options.connectOptions. Otherwise the browser is launched locally using the given launch options.

      Parameters:
      options - the Playwright Options (must not be null)
      browserType - the resolved BrowserType to launch/connect
      launchOptions - the resolved launch options (used when not connecting)
      Returns:
      a connected or launched Browser