jenkinsjunior
Posts: 3
Joined: Tue Aug 25, 2015 12:35 pm

I have added an existing item (png) into my project. I would like to know the correct way to use Imaging.Load() to be able to do validations based on this.

odklizec
Ranorex Guru
Posts: 6554
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Hi and welcome here,

If you want to compare your png file against a repo item, you can use code like this:

Code: Select all

image = Imaging.Load ("c:\path\to\file.png");
Validate.ContainsImage(RepoItemInfo, image, Imaging.FindOptions.Default, "Image validation", true);
Or like this, if you want to override Ranorex defaut FindOptions...

Code: Select all

Imaging.FindOptions MyFindOptions = new Imaging.FindOptions(0.95);
Validate.ContainsImage(RepoItemInfo, image, MyFindOptions, "Image validation", true);
You can find some more examples here:
http://www.ranorex.com/support/user-gui ... html#c3326
or by searching this forum
Last edited by odklizec on Tue Feb 07, 2017 9:00 am, edited 1 time in total.
Pavel Kudrys
Ranorex explorer at Descartes Systems

• Ranorex Snapshot. Learn how to create one >here<
• Ranorex xPath of problematic element(s)
• Ranorex version
• OS version
• HW configuration

jenkinsjunior
Posts: 3
Joined: Tue Aug 25, 2015 12:35 pm

For now I will be making do with using the default relative ranorex working directory path (bin\debug) and then getting it's grandparent, which is where Ranorex copied the files when they were imported. It works, but I suspect it will not once it is compiled.

This is because I cannot guarantee where the files will be on various test pcs. I need a way to perhaps reference these assets in a relative fashion, as if they were in the repo.

odklizec
Ranorex Guru
Posts: 6554
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

### Re: App get crashed while tap on element in iOS Instrumented app

If you already added the image file to your project, then you can now set it to always copy to output directory, which means the file will be copied (during build) to bin/debug or bin/release folder. In Projects view select the file and then in Properties set Copy to output dir. to Always.
image.jpg (95.61 KiB) Viewed 3822 times
Then you can use this code to get the path of debug/release dir...
string path = Ranorex.Core.Testing.TestSuite.WorkingDirectory;
Hope this helps?
Pavel Kudrys
Ranorex explorer at Descartes Systems

• Ranorex Snapshot. Learn how to create one >here<
• Ranorex xPath of problematic element(s)
• Ranorex version
• OS version
• HW configuration

jenkinsjunior
Posts: 3
Joined: Tue Aug 25, 2015 12:35 pm

Thank you so much, I think this will do it.

EDIT: Working, thank you.

sanoyag
Posts: 7
Joined: Fri May 12, 2017 9:40 am

Hi,

I came across this thread and have found out that this was what I needed for my current test case. However, I am stuck after the code for getting the path of the debug/release dir. How do I go through the path of where my Image is? Currently my image is stored on a folder called Images and it has been copied on the release dir since I specified the copy to output directory to always. I tried something like image = Imaging.Load ("c:\path\Images\specific_image.png"); yet I have encountered an error on unrecognized escape sequence. Am I doing it wrong? It's my first time actually trying the image validation and I'm still exploring..Thank you very much. Currently this is my code:

string path = Ranorex.Core.Testing.TestSuite.WorkingDirectory;
Imaging.FindOptions MyFindOptions = new Imaging.FindOptions(0.95);

Validate.ContainsImage(repo.App.Text1478Info,(System.Drawing.Bitmap) image, MyFindOptions, "Image validation", true);

odklizec
Ranorex Guru
Posts: 6554
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

You must use double backslash...

Code: Select all

image = Imaging.Load("c:\\path\\Images\\specific_image.png");
Or @ character in front of the path:

Code: Select all

image = Imaging.Load (@"c:\path\Images\specific_image.png");
Second solution is better, because you will most probably not use hardcoded path but variable? So it's better to go this way.
Pavel Kudrys
Ranorex explorer at Descartes Systems