Page 1 of 1

Failed to load bitmap from file when running on Ranorex Agen

Posted: Mon Mar 27, 2017 7:52 pm
by FourOfAKind
When running test cases that uses Imaging.Load() on Ranorex Agent, "Failed to load bitmap from file ..." occurs.

I have a test case that uses:
Bitmap Expected = Imaging.Load("..\\...\\Images\\Test52453Image1.png");

Runs perfectly fine locally (in Ranorex Studio).

Thanks for your help in advance.

Re: Failed to load bitmap from file when running on Ranorex Agen

Posted: Tue Mar 28, 2017 3:34 pm
by asdf
Hi FourOfAKind,

It seems that this problem is caused due to a wrong path to the image. Please make sure that the path to the image is correct. Also on the remote machine. I would suggest using the output directory for saving the image. Just add the image to your project and make sure that it will be copied to the output directory every time.
CopyToOutput.png
Afterwards, you could use the following code to get to this image.
string currDir = Directory.GetCurrentDirectory();
string image = @"\ImageName.jpeg";
Bitmap expected = Imaging.Load(currDir+image);
Make sure to set the namespace System.IO at the top of your code method.
using System.IO;
Hope this helps.

Re: Failed to load bitmap from file when running on Ranorex Agen

Posted: Tue Mar 28, 2017 9:20 pm
by FourOfAKind
The solution works! Thank you very much!

However, if it's possible, I'd like to have the images only load for the test cases that needs it.

As of now, every single image will be sent to the agent even with test cases that does not require it.

Thanks again for a quick and helpful reply!

Re: Failed to load bitmap from file when running on Ranorex Agen

Posted: Thu Mar 30, 2017 2:19 pm
by asdf
I'm glad that I could help. :)
Your approach could be achieved with a simple if condition. However, you will need a for example a variable that is set to true/false if the current testcase uses this image.

Code: Select all

if(TCusesImage == true)
{
     string currDir = Directory.GetCurrentDirectory();  
     string image = @"\ImageName.jpeg";  
     Bitmap expected = Imaging.Load(currDir+image); 
}
Hope this helps.

Re: Failed to load bitmap from file when running on Ranorex Agen

Posted: Thu Mar 30, 2017 9:50 pm
by FourOfAKind
Sorry for such a lousy explanation of what I wish to do.

Currently, all the images get sent to the Ranorex Agent (thru the zip file) even when running another test case that does not require the images.

Is it possible to only send the images to the Ranorex Agent if the test case being sent requires the images?

Again, thank you for such quick and accurate replies.

Re: Failed to load bitmap from file when running on Ranorex Agen

Posted: Wed Apr 05, 2017 1:36 pm
by asdf
Unfortunately, it is not possible to just send the images which are currently used by the testcase to the agent out of the box. The only way to achieve this would be to write some UserCode which check which testcases gets executed and except the screenshots accordingly. Since this is a lot of programming effort, I would suggest just deploying every screenshot of your project to the agent.