Page 1 of 1
Loading Image from a project in user code
Posted: Thu Aug 27, 2015 12:14 pm
by jenkinsjunior
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.
Re: Loading Image from a project in user code
Posted: Fri Aug 28, 2015 8:11 am
by odklizec
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
Re: Loading Image from a project in user code
Posted: Fri Aug 28, 2015 3:34 pm
by jenkinsjunior
Thanks for your response,
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.
Re: App get crashed while tap on element in iOS Instrumented app
Posted: Fri Aug 28, 2015 4:43 pm
by odklizec
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
Then you can use this code to get the path of debug/release dir...
string path = Ranorex.Core.Testing.TestSuite.WorkingDirectory;
Hope this helps?
Re: Loading Image from a project in user code
Posted: Wed Sep 02, 2015 3:49 pm
by jenkinsjunior
Thank you so much, I think this will do it.
EDIT: Working, thank you.
Re: Loading Image from a project in user code
Posted: Mon Jun 05, 2017 9:01 am
by sanoyag
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;
image = Imaging.Load ("c:\path\Images\specific_image.png");
Imaging.FindOptions MyFindOptions = new Imaging.FindOptions(0.95);
Validate.ContainsImage(repo.App.Text1478Info,(System.Drawing.Bitmap) image, MyFindOptions, "Image validation", true);
Please advise..
Thank you in advance
Re: Loading Image from a project in user code
Posted: Mon Jun 05, 2017 9:14 am
by odklizec
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.