Event handling

Ranorex Spy, Recorder, and Studio.
manish
Certified Professional
Certified Professional
Posts: 53
Joined: Fri Aug 10, 2018 12:46 pm

Event handling

Post by manish » Wed Mar 03, 2021 2:10 pm

Hi,

Is there something like OnError() or OnFail() event generated by ranorex which is trigerred that can be used to execute some commands after an error or failure is encountered. I do not want to use teardown method.

Thank you
Manish

User avatar
Mike K
Certified Professional
Certified Professional
Posts: 28
Joined: Wed Jun 28, 2017 5:58 pm

Re: Event handling

Post by Mike K » Sun Mar 28, 2021 9:15 pm

Hi Manish,

This can be handled in two ways. The first is to convert all the action items to code by selecting all and then using a try/action routine to trap errors. To convert action to code first select the action items then right-click. From the context menu select the convert option. The second method is easier. We don't need to convert actions to code. Just select the target actions that matter and right-click. From the context menu select 'Enable continue on fail'. This should do it.

Cheers,
Mike

doke
Posts: 15
Joined: Fri Mar 29, 2019 2:33 pm

Re: Event handling

Post by doke » Fri Apr 02, 2021 4:51 pm

Hi,

an example to run another recording when something fails:
converted mouse click to user code would look like :
public void Mouse_Click()
{
Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click at {X=0,Y=0}.");
Mouse.MoveTo(0, 0);
Mouse.Click(System.Windows.Forms.MouseButtons.Left);
}
modify this to

public void Mouse_Click()
{
try
{ // Block of code to try
Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click at {X=0,Y=0}.");
Mouse.MoveTo(0, 0);
Mouse.Click(System.Windows.Forms.MouseButtons.Left);
}
catch (Exception e)
{
// Block of code to handle errors
// Do something else when fails
Mouse.Click(System.Windows.Forms.MouseButtons.Left);
}
}
you acould even run another module :
see viewtopic.php?f=4&t=10089&p=53686#p53686