Compare validation images during a test
Compare validation images during a test
I use live feeds (TV images) as images that I need to validate and as so are continuously changing. Is there a way of creating a screenshot of an image at one point in the test and compare it later with another screenshot, knowing that the screenshot will be different every time the test is performed?
- Support Team
- Site Admin
- Posts: 12167
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Graz, Austria
Re: Compare validation images during a test
Hi GVLT,
This is possible by using Validate.CompareImage backward. Normally this method validates that two images are the same, but we can inverse the results to validate the image is different. Check out my example code below. You can customize some of the options as you see fit.
I hope this helps!
Regards,
Ned
This is possible by using Validate.CompareImage backward. Normally this method validates that two images are the same, but we can inverse the results to validate the image is different. Check out my example code below. You can customize some of the options as you see fit.
Code: Select all
// add reference to video element here
var repo = SampleSolutionRepository.Instance;
var element = repo.FormRun.Text1001;
// capture first reference screenshot
Bitmap referenceScreenshot = Ranorex.Imaging.CaptureImage(element);
Delay.Seconds(3); // may not be required, allows time for image to change
// validate image changed (this will capture a second image for comparison)
bool sameImage = Validate.CompareImage(
element,
referenceScreenshot,
Imaging.FindOptions.Parse("1;None;0,0,297,17;True;10000000;0ms"),
"Validating image changed",
new Validate.Options(){
ReportLevelOnFailure=ReportLevel.Debug,
ReportExpectedAndActualImages=Validate.ResultOption.Always,
ExceptionOnFail=false,
}
);
// report if images are different or not
if (sameImage)
Validate.Fail("Images are the same. (expected different image)");
else
Report.Success("Images are different.");
Regards,
Ned