Image Valiation with Code Module.

Ask general questions here.
Posts: 3
Joined: Tue Feb 19, 2019 2:01 pm

Image Valiation with Code Module.

Post by sepr8084 » Wed Mar 27, 2019 12:07 pm

Hello Team,

I am currently using trial version Ranorex 8. I struck with below issue while writing a test case. I tried online help but everything deals with Recording and not with code module.

I have created a test case with Code Module and not through Recordings. I have a below piece of code to validate image. I could successfully compare the image and I could see the difference in the Report. But even if the Image is not matching the report shows successful with Green pie diagram and not Red. I added validation screen shot in .rxrep file with file name : Screenshot1. I would like to know how to record the failure when the images are not matching with code module.

Attached a Report which shows successfull with an value 140 but actual value is 280. I wish to see Report failed. Is there a setting to be made or extend this code ?

If you need further information please let me know. Thank you.

What I found: I could find a solution in ... alidation/. The output is what I expect. But, the description for above is for Recording and not for code module. I could not see the ‘Report difference Image’ inside properties as described in above link. For which I need a support.

Code: Select all

namespace SussGUITestAutomation.TestCases.CircularGauge 
    [TestModule("31001416-BDDB-4879-9ACC-22EEBA993057", ModuleType.UserCode, 1)] 
    public class TC_CircularGaugeRangeCheck : TestCase, ITestModule 
              private readonly SussGUITestAutomationRepositoryFolders.TabPageCircularGaugeFolder _repoCircularGauge = 
        public override void Execute() 
                "compare image and validate the slider.", 
                $"Upper Value is defined.", 
                () => 
                SetValueAndValidate(140, _repoCircularGauge.Ranges.Upper_Container.Upper_EditInfo , _repoCircularGauge.Ranges.Upper_Container.UpperSliderInfo); 
                        _repoCircularGauge.RangeIndicatorPanelInfo.GetScreenshot1(), new Imaging.FindOptions(0.85), 
                        "Show Difference", new Validate.Options() {ReportDifferenceImages = Ranorex.Validate.ResultOption.Always, 
                            ReportSimilarity = Ranorex.Validate.ResultOption.Always} ); 
       private void SetValueAndValidate(int _value,RepoItemInfo _edit, RepoItemInfo _slider) 
            Report(Validate.Slider.HasExpectedValue(_slider, _value)); 
SussGUITestAutomation_20190327_104054.JPG (67.64 KiB) Viewed 638 times
validation screen shot in .rxrep file with file name : Screenshot1
screenshot1.JPG (131.24 KiB) Viewed 638 times

User avatar
Posts: 450
Joined: Fri Jul 15, 2016 1:35 pm

Re: Image Valiation with Code Module.

Post by Stub » Thu Mar 28, 2019 8:27 am

You are asking that the image comparison be at least an 85% match (0.85 in your code), whereas the report is saying that the images are actually just over 99% similar. You can see that in the actual (0.999....) vs expected figures shown in the report. An 85% match is an extremely loose comparison. An awful lot of image differences can be passed by that missing 15%.

User avatar
Ranorex Guru
Ranorex Guru
Posts: 6798
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Image Valiation with Code Module.

Post by odklizec » Thu Mar 28, 2019 8:41 am


Additionally to what Stub mentioned, I would suggest to create the image validation via recording and then simply convert the steps to user code, which you can eventually edit. This way you can quickly learn, how to do image validation via code.

Simply select the recording step (or steps) in Recording table, right click the selection and from the appeared context menu select Convert to user code. Hope this helps? ... tousercode
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration