Failed to load bitmap from file when running on Ranorex Agen

Bug reports.
FourOfAKind
Posts: 5
Joined: Mon Mar 27, 2017 7:49 pm

Failed to load bitmap from file when running on Ranorex Agen

Post by FourOfAKind » Mon Mar 27, 2017 7:52 pm

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.

asdf
Posts: 174
Joined: Mon Mar 21, 2016 3:16 pm

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

Post by asdf » Tue Mar 28, 2017 3:34 pm

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
CopyToOutput.png (2.41 KiB) Viewed 858 times
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.

FourOfAKind
Posts: 5
Joined: Mon Mar 27, 2017 7:49 pm

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

Post by FourOfAKind » Tue Mar 28, 2017 9:20 pm

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!

asdf
Posts: 174
Joined: Mon Mar 21, 2016 3:16 pm

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

Post by asdf » Thu Mar 30, 2017 2:19 pm

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.

FourOfAKind
Posts: 5
Joined: Mon Mar 27, 2017 7:49 pm

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

Post by FourOfAKind » Thu Mar 30, 2017 9:50 pm

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.

asdf
Posts: 174
Joined: Mon Mar 21, 2016 3:16 pm

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

Post by asdf » Wed Apr 05, 2017 1:36 pm

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.