Class CompareScreenshot
java.lang.Object
net.serenitybdd.screenplay.playwright.assertions.visual.CompareScreenshot
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
);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe actual screenshot comparison implementation. -
Method Summary
Modifier and TypeMethodDescriptionstatic CompareScreenshotCompare a screenshot of a specific element.static CompareScreenshotCompare a screenshot of a specific Target element.static CompareScreenshotofPage()Compare a full page screenshot.toBaseline(String baselineName) Specify the baseline name for comparison.
-
Method Details
-
ofPage
Compare a full page screenshot. -
of
Compare a screenshot of a specific element.- Parameters:
selector- The CSS or XPath selector
-
of
Compare a screenshot of a specific Target element.- Parameters:
target- The Target element
-
toBaseline
Specify the baseline name for comparison.- Parameters:
baselineName- The name for the baseline image (without extension)
-