Page 1 of 1

Code to break out of a Test Case

Posted: Wed Sep 06, 2017 9:21 am
by Fergal
Hi,

I have a TC in this format:

TC
- Recording Module A
- Recording Module B
- Recording Module C
- Recording Module D

I'd like to insert a code module between Recording Module A and Recording Module B, that will end and pass the TC, if a certain element exists. What code can I use to break out of the TC and not run the subsequent recording modules.

Edit: Using Ranorex 6.2.1 on Windows 7

Thanks

Re: Code to break out of a Test Case

Posted: Wed Sep 06, 2017 9:34 am
by odklizec
Hi,

I think the cleanest solution of your problem is enclosing modules B, C and D in a nested smart folder. Then you should setup a condition, which will run or ignore the smart folder, based of the variable/parameter filled via the code module you mentioned (placed before the smart folder with condition). I believe there is also a coded way to achieve what you want? But if I remember it correctly, it uses an internal API, which is not recommended to use ;) So using nested SF with condition is probably the best way.

Re: Code to break out of a Test Case

Posted: Wed Sep 06, 2017 11:22 am
by Fergal
Thanks for your suggestion and reply odklizec. Sorry but I should have said I am using Ranorex 6.2.1, so I don't think that's an option on this version.

Re: Code to break out of a Test Case

Posted: Wed Sep 06, 2017 11:45 am
by odklizec
Well, in this case, you still have two options...

You can still create a nested test case (placed after code module), and then disable/enable it from code, like this:

Code: Select all

TestSuite.Current.GetTestCase("TestCaseName").Checked = false;
And this sample skips all TestCase modules (uses internal API):
https://www.ranorex.com/forum/how-to-st ... tml#p24582
Hope this helps?

Re: Code to break out of a Test Case

Posted: Wed Sep 06, 2017 1:38 pm
by Fergal
Thanks very much Pavel. Your first option looks perfect, will work on that and reply back if I have any issues / questions.