Class VisualComparisonOptions

java.lang.Object
com.shaft.validation.VisualComparisonOptions
Direct Known Subclasses:
PlaywrightVisualComparisonOptions

public class VisualComparisonOptions extends Object
Options for the matchesScreenshot(...) visual-regression assertion, mirroring Playwright's toHaveScreenshot() options.

Build with create() and the fluent setters, then pass the result to assertThat(...).matchesScreenshot(options). The comparison runs when the terminal assertion is called.

driver.element().assertThat(By.id("logo"))
      .matchesScreenshot(VisualComparisonOptions.create()
              .maxDiffPixelRatio(0.01)
              .mask(By.id("timestamp")));
  • Constructor Details

    • VisualComparisonOptions

      public VisualComparisonOptions()
  • Method Details

    • create

      public static VisualComparisonOptions create()
      Returns:
      a new, empty options object to configure and pass to matchesScreenshot(...)
    • maxDiffPixels

      public VisualComparisonOptions maxDiffPixels(int maxDiffPixels)
      Caps the number of differing pixels allowed for the comparison to still pass.
      Parameters:
      maxDiffPixels - maximum allowed differing pixel count
      Returns:
      this options object, to continue chaining
    • maxDiffPixelRatio

      public VisualComparisonOptions maxDiffPixelRatio(double maxDiffPixelRatio)
      Caps the ratio of differing pixels (0.0-1.0) allowed for the comparison to still pass.
      Parameters:
      maxDiffPixelRatio - maximum allowed differing pixel ratio
      Returns:
      this options object, to continue chaining
    • mask

      public VisualComparisonOptions mask(org.openqa.selenium.By... masks)
      Excludes the region(s) covered by the given locators from the pixel comparison.
      Parameters:
      masks - locators of elements whose bounding boxes should be excluded from the diff
      Returns:
      this options object, to continue chaining
    • getMaxDiffPixels

      public Integer getMaxDiffPixels()
      Returns:
      the configured maximum differing pixel count, or null if unset
    • getMaxDiffPixelRatio

      public Double getMaxDiffPixelRatio()
      Returns:
      the configured maximum differing pixel ratio, or null if unset
    • getMaskLocators

      public List<org.openqa.selenium.By> getMaskLocators()
      Returns:
      the (possibly empty) list of locators whose regions are excluded from the diff