Page 1 of 1

Image Valiation with Code Module.

Posted: Wed Mar 27, 2019 12:07 pm
by sepr8084
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 https://www.ranorex.com/blog/enhanced-f ... 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 = 
        Repos.Gallery.TabPageList.TabPageCircularGauge; 
  
        public override void Execute() 
        { 
            
            DoStep( 
                1, 
                "compare image and validate the slider.", 
                $"Upper Value is defined.", 
                () => 
                { 
  
                SetValueAndValidate(140, _repoCircularGauge.Ranges.Upper_Container.Upper_EditInfo , _repoCircularGauge.Ranges.Upper_Container.UpperSliderInfo); 
                Ranorex.Validate.CompareImage(_repoCircularGauge.RangeIndicatorPanelInfo, 
                        _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(Do.Text.SetText(_edit,_value)); 
            Report(Do.Keyboard.Press(Keys.Tab)); 
            Report(Validate.Slider.HasExpectedValue(_slider, _value)); 
       } 
  
    }

Re: Image Valiation with Code Module.

Posted: Thu Mar 28, 2019 8:27 am
by Stub
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%.

Re: Image Valiation with Code Module.

Posted: Thu Mar 28, 2019 8:41 am
by odklizec
Hi,

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?
https://www.ranorex.com/help/latest/ran ... tousercode