Page 1 of 1

Overwrite ObjectNotFoundException

Posted: Fri Jan 25, 2019 12:27 pm
by Andymann
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.

Re: Overwrite ObjectNotFoundException

Posted: Mon Jan 28, 2019 10:01 am
by RobinHood42
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:

Re: Overwrite ObjectNotFoundException

Posted: Tue Jan 29, 2019 11:36 am
by Andymann
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?

Re: Overwrite ObjectNotFoundException

Posted: Thu Jan 31, 2019 1:20 pm
by RobinHood42
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

Re: Overwrite ObjectNotFoundException

Posted: Thu Jan 31, 2019 1:48 pm
by odklizec
Plus thorough and frequent search of this forum, which is full of similarly handy code snippets :D