java.lang.Object
net.serenitybdd.screenplay.playwright.assertions.visual.CompareScreenshot

public class CompareScreenshot extends Object
Perform visual regression testing by comparing screenshots to baseline images.

On first run, baseline images are created. On subsequent runs, screenshots are compared against the baselines and differences are reported.

Sample usage:

     // Compare full page screenshot
     actor.attemptsTo(CompareScreenshot.ofPage().toBaseline("homepage"));

     // Compare element screenshot
     actor.attemptsTo(CompareScreenshot.of("#header").toBaseline("header-component"));
     actor.attemptsTo(CompareScreenshot.of(NAVIGATION).toBaseline("nav-bar"));

     // With custom threshold (0.0 = exact match, 1.0 = any difference allowed)
     actor.attemptsTo(
         CompareScreenshot.ofPage()
             .toBaseline("dashboard")
             .withThreshold(0.1)  // Allow 10% difference
     );
 
  • Method Details

    • ofPage

      public static CompareScreenshot ofPage()
      Compare a full page screenshot.
    • of

      public static CompareScreenshot of(String selector)
      Compare a screenshot of a specific element.
      Parameters:
      selector - The CSS or XPath selector
    • of

      public static CompareScreenshot of(Target target)
      Compare a screenshot of a specific Target element.
      Parameters:
      target - The Target element
    • toBaseline

      public CompareScreenshot.ScreenshotComparison toBaseline(String baselineName)
      Specify the baseline name for comparison.
      Parameters:
      baselineName - The name for the baseline image (without extension)