Page 1 of 1

choosing what element to screenshot on failure

Posted: Thu Jan 23, 2014 4:06 pm
by hnporter
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!

Re: choosing what element to screenshot on failure

Posted: Thu Jan 23, 2014 4:40 pm
by krstcs
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);
}

Re: choosing what element to screenshot on failure

Posted: Thu Jan 23, 2014 7:31 pm
by hnporter
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.

Re: choosing what element to screenshot on failure

Posted: Thu Jan 23, 2014 8:17 pm
by krstcs
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.

Re: choosing what element to screenshot on failure

Posted: Fri Jan 24, 2014 2:15 pm
by hnporter
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.

Re: choosing what element to screenshot on failure

Posted: Mon Jan 27, 2014 2:38 pm
by mebner
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

Re: choosing what element to screenshot on failure

Posted: Wed Jan 29, 2014 6:24 pm
by hnporter
Thanks, I appreciate the feedback!