Anyway to exit out of recording?

Ask general questions here.
User avatar
Gunner1980
Posts: 89
Joined: Mon Apr 05, 2010 8:44 pm
Location: Austin, Texas

Anyway to exit out of recording?

Post by Gunner1980 » Fri Jan 14, 2011 8:26 pm

I basically have a test set up this way.

Program.cs

Code: Select all

recording1.start();
recording2.start();
recording3.start();
recording 1 has 12 steps in it.

lets say the test fails on step 4 of these 12 steps, I want to exit out of recording 1 and move onto recording2. If I use exception on fail it exits the entire program.cs I don't want it to do this. I also want to be able to exit out of more than just a function.

Is there anything that should exit me out of the recording but not the entire program?

User avatar
slavikf
Posts: 104
Joined: Mon Sep 13, 2010 9:07 pm
Location: Toronto, Canada
Contact:

Re: Anyway to exit out of recording?

Post by slavikf » Sat Jan 15, 2011 1:58 am

You can try ... catch your exception in Program.cs

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: Anyway to exit out of recording?

Post by artur_gadomski » Mon Jan 17, 2011 9:47 am

If you want your recordings to continue after an exception in one then like slavikf said surround each recording in try catch. Just remember that exiting a recording at unknown point can leave your environment in unknown state (some windows are open, or closed) and you need to clean that up in preparation for next recording if it assumes some state of environment.

If you want to exit recording and continue to next one on failed assertion then you might try to 'return' if assertion fails.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Anyway to exit out of recording?

Post by Support Team » Mon Jan 17, 2011 4:53 pm

Hi,

Please take a look to following post
http://www.ranorex.com/forum/executing- ... t1446.html

I think this exactly what you need.

Regards,
Peter
Ranorex Team
.
Image

costamesakid
Posts: 94
Joined: Tue Jun 16, 2009 10:27 pm

Re: Anyway to exit out of recording?

Post by costamesakid » Tue Feb 08, 2011 3:29 am

I have tried a few of these suggestions but cannot get the program to cease execution of a single recording.

Maybe some more information would be helpful? See below.

The tests we run are determined via command line arguments. For instance, '-test1 -test2 -test3' appended to the executable will run test1, test2, and then test3.

We have a particular function in the UserCode of 'test1' that checks to see if a certain object exists. If the object exists test1 continues, but if the object doesnt exist we would like to cease all processing of test1 and start with the next command line argument, in this case test2.

Tried Thread.ResetAbort but get a complier error. Also tried Environment.Exit(-1), but this will exit the entire test suite, without ever getting to the next test.

Thanks for the help. Much appreciated.

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: Anyway to exit out of recording?

Post by artur_gadomski » Tue Feb 08, 2011 7:44 am

This is a bit tricky. You want to exit an outer method from inner method. Something like this:
public void MyRecording() {
    // Recording code
    CheckSomeConditionUsercode();
    // Recording code
}

public void CheckSomeConditionUsercode() {
    if (someCondition) {
         //Leave recording
    }
}

You might be able to accomplish this by moving all the code to separate method and merging it with if statement. Then you will be able to leave this method whenever you please. Something like this:
public void SomeCustomTestMethod() {
    // Code copied from recording
    if (someCondition) {
        return;
    }
    // Code copied from recording
}
In Program.Main rather than calling Recording.Start() you would call SomeCustomTestMethod().

User avatar
sdaly
Posts: 238
Joined: Mon May 10, 2010 11:04 am
Location: Dundee, Scotland

Re: Anyway to exit out of recording?

Post by sdaly » Tue Feb 08, 2011 10:27 am

costmeakid, you just need to wrap your main test loop within a Try Catch block....

'main test loop

For Each Test in Tests
Try
'Invoke the test here
'test passed
Catch ex as Exception
'test failed
End Try

Next

If the function that is used by the tests catches the exception too then just Throw it again and the main Try Catch will catch it!