Page 1 of 1

Anyway to exit out of recording?

Posted: Fri Jan 14, 2011 8:26 pm
by Gunner1980
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?

Re: Anyway to exit out of recording?

Posted: Sat Jan 15, 2011 1:58 am
by slavikf
You can try ... catch your exception in Program.cs

Re: Anyway to exit out of recording?

Posted: Mon Jan 17, 2011 9:47 am
by artur_gadomski
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.

Re: Anyway to exit out of recording?

Posted: Mon Jan 17, 2011 4:53 pm
by Support Team
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

Re: Anyway to exit out of recording?

Posted: Tue Feb 08, 2011 3:29 am
by costamesakid
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.

Re: Anyway to exit out of recording?

Posted: Tue Feb 08, 2011 7:44 am
by artur_gadomski
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().

Re: Anyway to exit out of recording?

Posted: Tue Feb 08, 2011 10:27 am
by sdaly
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!