#![cfg(feature = "screenshot-diff")]
use image::{ImageBuffer, Rgba};
use playwright_cdp::assertions::{ScreenshotAssertOptions, expect};
fn encode_png(buf: &ImageBuffer<Rgba<u8>, Vec<u8>>) -> Vec<u8> {
let mut out = std::io::Cursor::new(Vec::new());
buf.write_to(&mut out, image::ImageFormat::Png).unwrap();
out.into_inner()
}
fn solid(color: [u8; 4], w: u32, h: u32) -> ImageBuffer<Rgba<u8>, Vec<u8>> {
ImageBuffer::from_fn(w, h, |_x, _y| Rgba(color))
}
#[test]
fn identical_images_are_an_exact_match() {
let img = solid([10, 20, 30, 255], 4, 4);
let bytes_a = encode_png(&img);
let bytes_b = encode_png(&img);
assert_eq!(bytes_a, bytes_b, "identical images should encode identically");
}
#[test]
fn options_builder_records_tolerance() {
let opts = ScreenshotAssertOptions::new()
.with_max_diff_pixels(5)
.with_threshold(0.1);
assert_eq!(opts.max_diff_pixels, Some(5));
assert_eq!(opts.threshold, Some(0.1));
}
#[test]
fn default_options_are_strict() {
let opts = ScreenshotAssertOptions::default();
assert_eq!(opts.max_diff_pixels, None);
assert_eq!(opts.threshold, None);
}
#[allow(dead_code)]
fn _assertions_compile(loc: playwright_cdp::Locator) {
let _ = expect(loc);
}