I have a checkbox object that Ranorex does not see as a checkbox object, so the Checked.Equals(true) option is not valid. What I was thinking of doing instead was to use image based validation to check if the checkbox is checked, and if not, double click the item to make sure it's checked.
Is there a way to use image based validation pass/fail outcome in a conditional statement? I have been toying around a bit with it, but can't seem to come up with a solution.
Use outcome of image based validation as a condition?
- Support Team
- Site Admin
- Posts: 12167
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Graz, Austria
Re: Use outcome of image based validation as a condition?
Hello,
You could use image-based validation to check if a checkbox is clicked or not.
Simply create a snapshot of your Repository Element (checked or unchecked) and use 'Validate.CompareImage' in your Recording to compare your element with your snapshot.
This will generate a region 'Image Feature Data' in your <Recording>.cs file.
You might need to adjust the similarity in the properties of your validation action.
You could use the following User Code:
Regards,
Markus (T)
You could use image-based validation to check if a checkbox is clicked or not.
Simply create a snapshot of your Repository Element (checked or unchecked) and use 'Validate.CompareImage' in your Recording to compare your element with your snapshot.
This will generate a region 'Image Feature Data' in your <Recording>.cs file.
You might need to adjust the similarity in the properties of your validation action.
You could use the following User Code:
bool isChecked = Validate.CompareImage(<RepoItemInfo>, <ScreenshotChecked>, new Imaging.FindOptions("yourSettings"), string "YourMessage", new Validate.Options("yourSettings"));Another method would be to store your screenshot on your file system and use Imaging.Compare:
bool isChecked = Imaging.Compare(<RepoItem>, <Bitmap>, findOpt);You could use a simple IF-statement to do some action if checkbox is checked.
Regards,
Markus (T)
Re: Use outcome of image based validation as a condition?
Hello Markus,
Thank you for getting back to me. Unfortunately when I try to make the image validation a bool, I get the compile error: "Cannot implicitly convert type 'void' to 'bool' (CS0029)."
I'm also using the ContainsImage validation as opposed to CompareImage if that makes a difference.
Thank you for getting back to me. Unfortunately when I try to make the image validation a bool, I get the compile error: "Cannot implicitly convert type 'void' to 'bool' (CS0029)."
I'm also using the ContainsImage validation as opposed to CompareImage if that makes a difference.
- Support Team
- Site Admin
- Posts: 12167
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Graz, Austria
Re: Use outcome of image based validation as a condition?
Hello,
It looks like that you use a method that doesn't return a bool value.
Please take a look at the several ways to use Validate.CompareImage in our API documentation.
Regards,
Markus (T)
It looks like that you use a method that doesn't return a bool value.
Please take a look at the several ways to use Validate.CompareImage in our API documentation.
Regards,
Markus (T)
Re: Use outcome of image based validation as a condition?
Hi Markus,
Thanks for your reply, the API really helped but I'm now stuck on another point.
I got the validation to work with Validate.ContainsImage with the following code:
What this code is doing is checking the items in Windows' "Disk Cleanup", and it works fine if the item is NOT checked, but if it's checked, it hard stops the rest of the items (even though I have it within a try/catch block) and I get the following report error:
Thanks for your reply, the API really helped but I'm now stuck on another point.
I got the validation to work with Validate.ContainsImage with the following code:
Code: Select all
var diskCleanup = repo.DiskCleanupForC.Table1000;
try {
//Validate if 'Downloaded Program Files' is checked.
bool valDPF = Validate.ContainsImage(diskCleanup.DownloadedProgramFilesInfo, DownloadedProgramFiles_Screenshot1, DownloadedProgramFiles_Screenshot1_Options, Validate.DefaultMessage, false);
What this code is doing is checking the items in Windows' "Disk Cleanup", and it works fine if the item is NOT checked, but if it's checked, it hard stops the rest of the items (even though I have it within a try/catch block) and I get the following report error:
Code: Select all
Image not found in element {Cell: Downloaded Program Files}
Last edited by kmck on Wed Aug 21, 2013 2:31 pm, edited 1 time in total.
Re: Use outcome of image based validation as a condition?
Actually, I used Validate.CompareImage instead of Validate.ContainsImage and it works fine now
I guess my last question would be, is there a way to suppress the module failure if the validated image doesn't exist? I want it to bind the validation to the Boolean and use that Boolean variable to determine if another block of code should execute, but I don't want it to fail the test case. I've tried using a try/catch block, but it doesn't seem to be doing the trick.

I guess my last question would be, is there a way to suppress the module failure if the validated image doesn't exist? I want it to bind the validation to the Boolean and use that Boolean variable to determine if another block of code should execute, but I don't want it to fail the test case. I've tried using a try/catch block, but it doesn't seem to be doing the trick.
- Support Team
- Site Admin
- Posts: 12167
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Graz, Austria
Re: Use outcome of image based validation as a condition?
Hi,
You could for instance change the Validate Options:
Markus
You could for instance change the Validate Options:
Validate.Options options = new Validate.Options(); options.ExceptionOnFail = false; options.ReportLevelOnFailure = ReportLevel.Info; // you can also set it to another level bool returnValue = Validate.CompareImage(diskCleanup.DownloadedProgramFilesInfo, DownloadedProgramFiles_Screenshot1, DownloadedProgramFiles_Screenshot1_Options,Validate.DefaultMessage, options); if(returnValue == false){ Report.Info("The Image doesn't match!"); }Regards,
Markus
Re: Use outcome of image based validation as a condition?
Hi Markus,
Thank you for that! Using the new instance of Validate.Options worked great.
Thank you for that! Using the new instance of Validate.Options worked great.
- Support Team
- Site Admin
- Posts: 12167
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Graz, Austria
Re: Use outcome of image based validation as a condition?
Re: Use outcome of image based validation as a condition?
The Validate Options works well in my application. Thanks!