Compare validation images during a test

Ask general questions here.
GVLT
Posts: 1
Joined: Wed Jul 22, 2020 11:26 am

Compare validation images during a test

Post by GVLT » Wed Jul 22, 2020 11:33 am

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?

User avatar
Support Team
Site Admin
Site Admin
Posts: 12143
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Compare validation images during a test

Post by Support Team » Thu Jul 23, 2020 3:12 pm

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.

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.");
I hope this helps!

Regards,
Ned
.
Image