Log image in report

Ranorex Spy, Recorder, and Studio.
chris.riether
Posts: 3
Joined: Tue May 15, 2018 3:04 pm

Log image in report

Post by chris.riether » Tue May 15, 2018 3:50 pm

Hi there,

I'm using Ranorex 6.0.2.
I have a test scenario, where I load an image from a device into an WPF window for displaying. Now I want to log this image into the Ranorex report.

Found some suggestions from Version 2.x that IReportLogger.LogData() should work with System.Drawing.Bitmap (and only this type of data).
In fact, if I use any other image-object-type its fullqualified type name is logged. If I use Bitmap, the log entry is ignored AT ALL.

Next suggestion said, with IReportLogger.Screenshot() or IReportLogger.Snapshot() it would be possible to capture a single window. But it seems that these methods do not accept a Xaml-Window as Ranorex.Core.Element. Found hints for activating WPF in Global Settings. Is active. No Change.

I do not want a screenshot over all my displays just to capture a part of my tiny window.

Is there a proper way to append an image (from file, stream, memory-image, what-so-ever) into the report, without updating to Ranorex 8?
(Don't want to trigger a validation process, again, just for some evidence images)

Thanks and best wishes,
Chris

ahoisl
Certified Professional
Certified Professional
Posts: 125
Joined: Fri Sep 07, 2007 8:16 am

Re: Log image in report

Post by ahoisl » Tue May 15, 2018 8:59 pm

Adding an image to the report using the Report.LogData method should work (at least) since Ranorex 3.0, e.g. using the following code:
Report.LogData(ReportLevel.Info, "Image", Ranorex.Imaging.Load(@"<fullPathToImageOnDisk>"));
chris.riether wrote:Next suggestion said, with IReportLogger.Screenshot() or IReportLogger.Snapshot() it would be possible to capture a single window. But it seems that these methods do not accept a Xaml-Window as Ranorex.Core.Element. Found hints for activating WPF in Global Settings. Is active. No Change.
Not sure what you mean by "Xaml-Window"; how do you pass the window to the Screenshot method? You need Ranorex UI element to pass to these functions; usually you get such an instance by searching for an element using a RanoreXPath that you generate upfront with Ranorex Spy.
FYI, the Imaging class provides a set of methods to create screenshots as well.

Regards,
Alex
Ranorex Team

chris.riether
Posts: 3
Joined: Tue May 15, 2018 3:04 pm

Re: Log image in report

Post by chris.riether » Wed May 16, 2018 9:54 am

Hi Alex!

The provided code snippet works great! Thanks a lot!

Is there an equivalent wrapper for images in memory, e.g. System.Drawing.Bitmap, instead of file? Just for optimization. Now i have to save it, so the Report can load it, to save it, again.

What I meant with "Xaml-Window": if I create a window component with WPF XAML. It's not a Ranorex.Core.Element. So if I call IReport.Snapshot(myWindow) it doesn't work, clearly. Can it be wrapped for the snapshot? Or is there another magic? Haven't found any docu for that.

When browsing with the Spy I get a list of currently available Windows and GUI elements. Guess, I could somehow use the "ranorexobjectid" or something to get grip of the mentioned path. But it sounds like that I would have to step through the test cases to the point, the window was generated, generate the path reference, so I could use it in the next run. Sounds strange...

Due to the fact that I do not test my GUI but just want to use it as evidence for my device under test, it sounds not suitable. I want to generate a multitude of tests, where these Windows get dynamically generated as needed, captured, and destroyed again.

Thanks for the tip with the Imaging class. But what I've seen, by now, still needs an Ranorex.Core.Element as target.

Thanks a lot, again,
greate help,
Chris

ahoisl
Certified Professional
Certified Professional
Posts: 125
Joined: Fri Sep 07, 2007 8:16 am

Re: Log image in report

Post by ahoisl » Wed May 16, 2018 10:47 am

chris.riether wrote:Is there an equivalent wrapper for images in memory, e.g. System.Drawing.Bitmap, instead of file? Just for optimization. Now i have to save it, so the Report can load it, to save it, again.
If you look closely at the code, you see that the code just loads an image from a file. If you already have a file loaded, just replace that code ("Ranorex.Imaging.Load") with the variable name that stores your image.
chris.riether wrote:What I meant with "Xaml-Window": if I create a window component with WPF XAML. It's not a Ranorex.Core.Element. So if I call IReport.Snapshot(myWindow) it doesn't work, clearly. Can it be wrapped for the snapshot? Or is there another magic? Haven't found any docu for that.
This is an uncommon thing for Ranorex scripts. However, the imaging class provides a CaptureDesktopImage method where you can just pass in the window rectangle, i.e. it's location on screen, and the method will return a screenshot Bitmap. So just get the rectangle from your XAML window and pass it into that method, then you should get a screenshot bitmap back.

Regards,
Alex
Ranorex Team

chris.riether
Posts: 3
Joined: Tue May 15, 2018 3:04 pm

Re: Log image in report

Post by chris.riether » Wed May 16, 2018 1:28 pm

Hi!
Thanks a very lot! Now, I've got all I needed.

The reason why LogData with just the bitmap variable didn't work must have been some little bug by me copying the bitmap out of the XAML image. Fixed it. Now it works. Thanks for hinting me to snoop there.
And the CaptureDesktopImage with Rectangle works, too.

Great work!
Best wishes,
Chris