Overwrite ObjectNotFoundException

Ranorex Spy, Recorder, and Studio.
User avatar
Andymann
Posts: 50
Joined: Wed Jul 27, 2016 12:22 pm
Location: Hamburg
Contact:

Overwrite ObjectNotFoundException

Post by Andymann » Fri Jan 25, 2019 12:27 pm

Hi Everybody,

I'd like to know if there is a chance to overwrite (override?) Ranorex's ObjectNotFoundException to always be a general RanorexException.
Background: We are using Ranorex together with Aqua (Testmanagement Tool) and Aqua only reacts to a "RanorexException"; it keeps on processing the testcase when Ranorex, for example, creates an ObjectNotFoundException. That's not sensible and certainly needs to be addressed on Aqua's side but for the time being I simply need some workaround.
Vorsprung durch Wahnsinn
www.Doktor-Andy.de

User avatar
RobinHood42
Posts: 277
Joined: Fri Jan 09, 2015 3:24 pm

Re: Overwrite ObjectNotFoundException

Post by RobinHood42 » Mon Jan 28, 2019 10:01 am

Hi,

The best way I found to throw a custom exception in case of an element not found, is to use the ActivityStack (internal API - so no docu available and can change in any Ranorex update). The code snippet is intended to be used within a global teardown section of your test:
Ranorex.Core.Reporting.ActivityStack.Instance.VisitAll(a =>
                         {
                             var act = a as TestContainerActivity;
                             if (act != null)
                             {
                                 if (act.ResultSummary.Contains("Failed to find item"))
                                 {
                                     throw new RanorexException("MyCustomRxException");
                                 }
                             }
                             return true;
                         });
Cheers,
Robin :mrgreen:

User avatar
Andymann
Posts: 50
Joined: Wed Jul 27, 2016 12:22 pm
Location: Hamburg
Contact:

Re: Overwrite ObjectNotFoundException

Post by Andymann » Tue Jan 29, 2019 11:36 am

Hi Robin,

thanks a lot for the quick response.
Can you give me aother quick hint where I can find 'TestContainerActivity' (using directive)?
[Update]got it: Ranorex.Core.Reporting.TestContainerActivity [/Update]


And: how on earth does someone know about those deeply burried internals?
Vorsprung durch Wahnsinn
www.Doktor-Andy.de

User avatar
RobinHood42
Posts: 277
Joined: Fri Jan 09, 2015 3:24 pm

Re: Overwrite ObjectNotFoundException

Post by RobinHood42 » Thu Jan 31, 2019 1:20 pm

Hi,

Great !
how on earth does someone know about those deeply burried internals?
Years of usage of Ranorex and some trial and error :wink:

Cheers,
Robin

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 4421
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Overwrite ObjectNotFoundException

Post by odklizec » Thu Jan 31, 2019 1:48 pm

Plus thorough and frequent search of this forum, which is full of similarly handy code snippets :D
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration