choosing what element to screenshot on failure

Ask general questions here.
hnporter
Posts: 18
Joined: Thu Jan 16, 2014 3:34 pm

choosing what element to screenshot on failure

Post by hnporter » Thu Jan 23, 2014 4:06 pm

I understand that there's various ways to disable screenshots on Report.Failure (questions have been posted to the forum on this in the past), but what I'd like to do is tell Ranorex which repository element to screenshot in case of a specific failure. By default, it wants to screenshot the entire screen, but when I call Report.Failure directly, I want it to focus on a specific repo element. Is this possible? Right now, I have a specific failure condition I'm targeting, so can get by with calling Report.Screenshot directly, but I don't necessarily want to disable failure screenshots entirely (just in case an unanticipated failure occurs). Thanks!

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: choosing what element to screenshot on failure

Post by krstcs » Thu Jan 23, 2014 4:40 pm

Use Report.Screenshot(Element). Just pass in the element you want to grab.

Code: Select all

DivTag dt = "//div[@id='MyDivTag']";

if (!dt.InnerText.Equals("Success")) {
  Report.Screenshot(dt.Element);
}
Shortcuts usually aren't...

hnporter
Posts: 18
Joined: Thu Jan 16, 2014 3:34 pm

Re: choosing what element to screenshot on failure

Post by hnporter » Thu Jan 23, 2014 7:31 pm

Thanks for the quick reply! As I mentioned in the initial post, I am already using Report.Screenshot directly; my concern is by disabling failure screenshots entirely, I will not get screenshots in situations that I haven't specifically gameplanned for. I am wanting to know if there's some way to override what screenshot is taken when the default Report.Failure is called.

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: choosing what element to screenshot on failure

Post by krstcs » Thu Jan 23, 2014 8:17 pm

I'm going to guess the answer is no.

Why do you want to capture specific elements? Is it a size issue? Are you just wanting to cut out extraneous visual artifacts?

If you are just wanting to see the actual value when it isn't correct, the screenshot that IS captured should show you that, since, by default, Ranorex attempts to make an element visible, and the failed element would be on screen.

The big problem here is if you set a new default and it fails because the element is not visible or not present (doesn't exist), Ranorex won't be able to screenshot it because it isn't there, so you will probably end up with ANOTHER exception and it still won't grab a screenshot.


So, not sure why you need/want to do this every time. The default action will probably be better for 99% of scenarios, and if you are actually in the 1%, I would think that it would be better to write your own code that handles that one thing you need.
Shortcuts usually aren't...

hnporter
Posts: 18
Joined: Thu Jan 16, 2014 3:34 pm

Re: choosing what element to screenshot on failure

Post by hnporter » Fri Jan 24, 2014 2:15 pm

I don't want a new default (because I wouldn't want Ranorex stymied for the reason you described), I would just have liked a way to pass in what I want to screenshot as an argument. It would be nice if Report.Failure offered optional arguments to implement this if desired. Something like:

Report.Failure("This didn't work", repo.myApp.myCell, false)

It's honestly not a huge deal; my issue is the app I'm testing is pretty small, and since a failure captures the entire screen by default, it can be a little hard to zero in on what failed visually. Thanks again for your help.

User avatar
mebner
Posts: 61
Joined: Tue Dec 17, 2013 6:42 pm

Re: choosing what element to screenshot on failure

Post by mebner » Mon Jan 27, 2014 2:38 pm

Hi,

Thanks for the suggestion!
We will discuss this feature internally, but I cannot guarantee that it will be implemented, since this could cause troubles in case the passed repository item doesn't exist.

Regards,
Markus

hnporter
Posts: 18
Joined: Thu Jan 16, 2014 3:34 pm

Re: choosing what element to screenshot on failure

Post by hnporter » Wed Jan 29, 2014 6:24 pm

Thanks, I appreciate the feedback!