Image Valiation with Code Module.

Ask general questions here.
sepr8084
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 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)); 
       } 
  
    }
Attachments
SussGUITestAutomation_20190327_104054.JPG
SussGUITestAutomation_20190327_104054.JPG (67.64 KiB) Viewed 67 times
screenshot1.JPG
validation screen shot in .rxrep file with file name : Screenshot1
screenshot1.JPG (131.24 KiB) Viewed 67 times

User avatar
Stub
Posts: 205
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
odklizec
Ranorex Guru
Ranorex Guru
Posts: 4549
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

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
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