Utilities for screenshot-based testing assertions. More...
#include <screenshot_assertion.h>

Public Types | |
| using | CaptureCallback |
Public Member Functions | |
| ScreenshotAssertion () | |
| ~ScreenshotAssertion ()=default | |
| void | SetConfig (const ComparisonConfig &config) |
| const ComparisonConfig & | GetConfig () const |
| void | SetCaptureCallback (CaptureCallback callback) |
| absl::StatusOr< ComparisonResult > | AssertMatchesReference (const std::string &reference_path) |
| Assert current screen matches a reference image file. | |
| absl::StatusOr< ComparisonResult > | AssertMatchesScreenshot (const Screenshot &expected) |
| Assert current screen matches another Screenshot object. | |
| absl::StatusOr< ComparisonResult > | AssertRegionMatches (const std::string &reference_path, const ScreenRegion ®ion) |
| Assert a specific region matches reference. | |
| absl::StatusOr< ComparisonResult > | AssertChanged (const std::string &baseline_name) |
| Assert screen has changed since baseline. | |
| absl::StatusOr< ComparisonResult > | AssertUnchanged (const std::string &baseline_name) |
| Assert screen has NOT changed since baseline. | |
| absl::Status | CaptureBaseline (const std::string &name) |
| Capture and store a baseline screenshot. | |
| absl::Status | SaveAsReference (const std::string &path) |
| Save current screen as a new reference image. | |
| absl::StatusOr< Screenshot > | LoadReference (const std::string &path) |
| Load a reference image from file. | |
| absl::StatusOr< Screenshot > | GetBaseline (const std::string &name) const |
| Get a previously captured baseline. | |
| void | ClearBaselines () |
| Clear all captured baselines. | |
| ComparisonResult | Compare (const Screenshot &actual, const Screenshot &expected) |
| Compare two screenshots. | |
| ComparisonResult | CompareRegion (const Screenshot &actual, const Screenshot &expected, const ScreenRegion ®ion) |
| Compare specific regions of two screenshots. | |
| absl::StatusOr< std::string > | GenerateDiffImage (const Screenshot &actual, const Screenshot &expected, const std::string &output_path) |
| Generate a visual diff image. | |
| absl::StatusOr< bool > | AssertPixelColor (int x, int y, uint8_t r, uint8_t g, uint8_t b, int tolerance=10) |
| Assert pixel at (x, y) has expected color. | |
| absl::StatusOr< bool > | AssertRegionContainsColor (const ScreenRegion ®ion, uint8_t r, uint8_t g, uint8_t b, float min_coverage=0.1f) |
| Assert region contains a specific color. | |
| absl::StatusOr< bool > | AssertRegionExcludesColor (const ScreenRegion ®ion, uint8_t r, uint8_t g, uint8_t b, int tolerance=10) |
| Assert region does NOT contain a specific color. | |
| absl::StatusOr< Screenshot > | CaptureScreen () |
| Capture current screen and return it. | |
Static Public Member Functions | |
| static absl::Status | SaveScreenshot (const Screenshot &screenshot, const std::string &path) |
| Save screenshot to file (PNG format). | |
| static absl::StatusOr< Screenshot > | LoadScreenshot (const std::string &path) |
| Load screenshot from file. | |
Private Member Functions | |
| ComparisonResult | ComparePixelExact (const Screenshot &actual, const Screenshot &expected, const ScreenRegion ®ion) |
| ComparisonResult | ComparePerceptualHash (const Screenshot &actual, const Screenshot &expected) |
| ComparisonResult | CompareStructural (const Screenshot &actual, const Screenshot &expected) |
| bool | ColorsMatch (uint8_t r1, uint8_t g1, uint8_t b1, uint8_t r2, uint8_t g2, uint8_t b2, int threshold) const |
| std::vector< ScreenRegion > | FindDifferingRegions (const Screenshot &actual, const Screenshot &expected, int threshold) |
Private Attributes | |
| ComparisonConfig | config_ |
| CaptureCallback | capture_callback_ |
| std::unordered_map< std::string, Screenshot > | baselines_ |
Utilities for screenshot-based testing assertions.
Provides tools for capturing, comparing, and asserting screenshot content for visual regression testing and AI-assisted verification.
Usage:
Definition at line 121 of file screenshot_assertion.h.
Definition at line 131 of file screenshot_assertion.h.
|
default |
|
default |
|
inline |
Definition at line 127 of file screenshot_assertion.h.
References config_.
|
inline |
Definition at line 128 of file screenshot_assertion.h.
References config_.
|
inline |
Definition at line 133 of file screenshot_assertion.h.
References capture_callback_.
| absl::StatusOr< ComparisonResult > yaze::test::ScreenshotAssertion::AssertMatchesReference | ( | const std::string & | reference_path | ) |
Assert current screen matches a reference image file.
Definition at line 15 of file screenshot_assertion.cc.
References CaptureScreen(), Compare(), config_, LoadReference(), and yaze::test::ComparisonConfig::tolerance.

| absl::StatusOr< ComparisonResult > yaze::test::ScreenshotAssertion::AssertMatchesScreenshot | ( | const Screenshot & | expected | ) |
Assert current screen matches another Screenshot object.
Definition at line 33 of file screenshot_assertion.cc.
References CaptureScreen(), Compare(), config_, and yaze::test::ComparisonConfig::tolerance.

| absl::StatusOr< ComparisonResult > yaze::test::ScreenshotAssertion::AssertRegionMatches | ( | const std::string & | reference_path, |
| const ScreenRegion & | region ) |
Assert a specific region matches reference.
Definition at line 46 of file screenshot_assertion.cc.
References CaptureScreen(), CompareRegion(), config_, LoadReference(), and yaze::test::ComparisonConfig::tolerance.

| absl::StatusOr< ComparisonResult > yaze::test::ScreenshotAssertion::AssertChanged | ( | const std::string & | baseline_name | ) |
Assert screen has changed since baseline.
Definition at line 64 of file screenshot_assertion.cc.
References CaptureScreen(), Compare(), config_, GetBaseline(), and yaze::test::ComparisonConfig::tolerance.

| absl::StatusOr< ComparisonResult > yaze::test::ScreenshotAssertion::AssertUnchanged | ( | const std::string & | baseline_name | ) |
Assert screen has NOT changed since baseline.
Definition at line 83 of file screenshot_assertion.cc.
References CaptureScreen(), Compare(), config_, GetBaseline(), and yaze::test::ComparisonConfig::tolerance.

| absl::Status yaze::test::ScreenshotAssertion::CaptureBaseline | ( | const std::string & | name | ) |
Capture and store a baseline screenshot.
Definition at line 101 of file screenshot_assertion.cc.
References baselines_, CaptureScreen(), and LOG_DEBUG.

| absl::Status yaze::test::ScreenshotAssertion::SaveAsReference | ( | const std::string & | path | ) |
Save current screen as a new reference image.
Definition at line 114 of file screenshot_assertion.cc.
References CaptureScreen(), and SaveScreenshot().

| absl::StatusOr< Screenshot > yaze::test::ScreenshotAssertion::LoadReference | ( | const std::string & | path | ) |
Load a reference image from file.
Definition at line 123 of file screenshot_assertion.cc.
References LoadScreenshot().
Referenced by AssertMatchesReference(), and AssertRegionMatches().

| absl::StatusOr< Screenshot > yaze::test::ScreenshotAssertion::GetBaseline | ( | const std::string & | name | ) | const |
Get a previously captured baseline.
Definition at line 128 of file screenshot_assertion.cc.
References baselines_.
Referenced by AssertChanged(), and AssertUnchanged().
|
inline |
Clear all captured baselines.
Definition at line 195 of file screenshot_assertion.h.
References baselines_.
| ComparisonResult yaze::test::ScreenshotAssertion::Compare | ( | const Screenshot & | actual, |
| const Screenshot & | expected ) |
Compare two screenshots.
Definition at line 138 of file screenshot_assertion.cc.
References CompareRegion(), and yaze::test::ScreenRegion::FullScreen().
Referenced by AssertChanged(), AssertMatchesReference(), AssertMatchesScreenshot(), and AssertUnchanged().

| ComparisonResult yaze::test::ScreenshotAssertion::CompareRegion | ( | const Screenshot & | actual, |
| const Screenshot & | expected, | ||
| const ScreenRegion & | region ) |
Compare specific regions of two screenshots.
Definition at line 143 of file screenshot_assertion.cc.
References yaze::test::ComparisonConfig::algorithm, ComparePerceptualHash(), ComparePixelExact(), CompareStructural(), yaze::test::ComparisonResult::comparison_time, config_, yaze::test::ComparisonResult::diff_image_path, yaze::test::ComparisonConfig::diff_output_dir, yaze::test::ComparisonResult::differing_pixels, yaze::test::ComparisonResult::error_message, yaze::test::ComparisonConfig::generate_diff_image, GenerateDiffImage(), yaze::test::Screenshot::IsValid(), yaze::test::ComparisonConfig::kPerceptualHash, yaze::test::ComparisonConfig::kPixelExact, and yaze::test::ComparisonConfig::kStructuralSim.
Referenced by AssertRegionMatches(), and Compare().
| absl::StatusOr< std::string > yaze::test::ScreenshotAssertion::GenerateDiffImage | ( | const Screenshot & | actual, |
| const Screenshot & | expected, | ||
| const std::string & | output_path ) |
Generate a visual diff image.
Definition at line 274 of file screenshot_assertion.cc.
References yaze::test::ComparisonConfig::color_threshold, ColorsMatch(), config_, yaze::test::Screenshot::data, yaze::test::Screenshot::GetPixelIndex(), yaze::test::Screenshot::height, SaveScreenshot(), and yaze::test::Screenshot::width.
Referenced by CompareRegion().

| absl::StatusOr< bool > yaze::test::ScreenshotAssertion::AssertPixelColor | ( | int | x, |
| int | y, | ||
| uint8_t | r, | ||
| uint8_t | g, | ||
| uint8_t | b, | ||
| int | tolerance = 10 ) |
Assert pixel at (x, y) has expected color.
| x | X coordinate |
| y | Y coordinate |
| r | Expected red (0-255) |
| g | Expected green (0-255) |
| b | Expected blue (0-255) |
| tolerance | Per-channel tolerance |
Definition at line 325 of file screenshot_assertion.cc.
References CaptureScreen(), and ColorsMatch().

| absl::StatusOr< bool > yaze::test::ScreenshotAssertion::AssertRegionContainsColor | ( | const ScreenRegion & | region, |
| uint8_t | r, | ||
| uint8_t | g, | ||
| uint8_t | b, | ||
| float | min_coverage = 0.1f ) |
Assert region contains a specific color.
Definition at line 341 of file screenshot_assertion.cc.
References CaptureScreen(), yaze::test::ComparisonConfig::color_threshold, ColorsMatch(), config_, yaze::test::ScreenRegion::height, yaze::test::ScreenRegion::width, yaze::test::ScreenRegion::x, and yaze::test::ScreenRegion::y.
Referenced by AssertRegionExcludesColor().

| absl::StatusOr< bool > yaze::test::ScreenshotAssertion::AssertRegionExcludesColor | ( | const ScreenRegion & | region, |
| uint8_t | r, | ||
| uint8_t | g, | ||
| uint8_t | b, | ||
| int | tolerance = 10 ) |
Assert region does NOT contain a specific color.
Definition at line 371 of file screenshot_assertion.cc.
References AssertRegionContainsColor().

| absl::StatusOr< Screenshot > yaze::test::ScreenshotAssertion::CaptureScreen | ( | ) |
Capture current screen and return it.
Definition at line 381 of file screenshot_assertion.cc.
References capture_callback_.
Referenced by AssertChanged(), AssertMatchesReference(), AssertMatchesScreenshot(), AssertPixelColor(), AssertRegionContainsColor(), AssertRegionMatches(), AssertUnchanged(), CaptureBaseline(), and SaveAsReference().
|
static |
Save screenshot to file (PNG format).
Definition at line 388 of file screenshot_assertion.cc.
References yaze::test::Screenshot::data, yaze::test::Screenshot::height, LOG_DEBUG, and yaze::test::Screenshot::width.
Referenced by GenerateDiffImage(), and SaveAsReference().
|
static |
Load screenshot from file.
Definition at line 414 of file screenshot_assertion.cc.
References yaze::test::Screenshot::data, yaze::test::Screenshot::height, yaze::test::Screenshot::source, and yaze::test::Screenshot::width.
Referenced by LoadReference().
|
private |
Definition at line 187 of file screenshot_assertion.cc.
References yaze::test::ComparisonConfig::color_threshold, ColorsMatch(), config_, yaze::test::Screenshot::data, yaze::test::ComparisonResult::difference_percentage, yaze::test::ComparisonResult::differing_pixels, yaze::test::Screenshot::GetPixelIndex(), yaze::test::ScreenRegion::height, yaze::test::Screenshot::height, yaze::test::ComparisonConfig::ignore_regions, yaze::test::ComparisonResult::similarity, yaze::test::ComparisonResult::total_pixels, yaze::test::ScreenRegion::width, yaze::test::Screenshot::width, yaze::test::ScreenRegion::x, and yaze::test::ScreenRegion::y.
Referenced by CompareRegion().

|
private |
Definition at line 256 of file screenshot_assertion.cc.
References yaze::test::ComparisonResult::error_message.
Referenced by CompareRegion().
|
private |
Definition at line 265 of file screenshot_assertion.cc.
References yaze::test::ComparisonResult::error_message.
Referenced by CompareRegion().
|
private |
Definition at line 434 of file screenshot_assertion.cc.
Referenced by AssertPixelColor(), AssertRegionContainsColor(), ComparePixelExact(), and GenerateDiffImage().
|
private |
Definition at line 441 of file screenshot_assertion.cc.
|
private |
Definition at line 269 of file screenshot_assertion.h.
Referenced by AssertChanged(), AssertMatchesReference(), AssertMatchesScreenshot(), AssertRegionContainsColor(), AssertRegionMatches(), AssertUnchanged(), ComparePixelExact(), CompareRegion(), GenerateDiffImage(), GetConfig(), and SetConfig().
|
private |
Definition at line 270 of file screenshot_assertion.h.
Referenced by CaptureScreen(), and SetCaptureCallback().
|
private |
Definition at line 271 of file screenshot_assertion.h.
Referenced by CaptureBaseline(), ClearBaselines(), and GetBaseline().