Page 1 of 1

How to stop test case/ignore next iterations

Posted: Fri Mar 07, 2014 9:28 am
by odklizec
Hi,

I have most of my test cases set with the Error behavior set to Continue with iteration and when possible, I handle all potential errors with "soft" exceptions, to make the test cases to continue with next iterations. However, in certain cases, I want to kill the Test case and ignore all the remaining iterations. Unfortunately, I cannot find a way to do so.

For example, I have a method, which detects if the application is still present/active. This method is called at various places in each iteration. If the method detects that the application is not available, it should kill the test case/all its remaining iterations. Here is what I already tried so far:
throw new Ranorex.ValidationException();

throw new RanorexException();

throw new Exception();

Validate.IsFalse(true);
All these options terminates the actual iteration, however, the test case still continues with the next iteration.

The reason why I'm trying to kill the TestCase/ignore remaining iterations is that running iterations, with no hope to finish them correctly, is a waste of time. And at second, each exception thrown during each iteration saves screenshot to report, which makes the reports huuuuuge, especially in case of high number of failed iterations. Any idea how to solve that? I'm sure there must be a command to simply stop/kill the given TestCase?

So far, I'm using Rx 4.1.5.

BTW, I've tried to solve terminating iteration in the past and I found a solution to do so for single iteration (discussed here). However, that problem was something else. At that time, I just wanted to kill single iteration and then continue with the next one and this one from second thread ;) But now I just want to kill whole test case.

Re: How to stop test case/ignore next iterations

Posted: Mon Mar 10, 2014 4:35 pm
by Support Team
Hi odklizec,

I created a small sample which allows you to disable all test case entries within your current test case. In other words you skip every iteration of your current test case after the code snippet because no enabled test case entries (recordings, usercode modules) are available. I suppose that’s what you are looking for :wink:
var testcase = (TestCase)TestCase.Current;
        	
        	foreach(TestSuiteModule a in testcase.AllModules)
        	{
        		a.Enabled = false;
        	}

Please note that undocumented API methods are used. It is not recommended and we do not guarantee for any side-effects.


Regards,
Robert

Re: How to stop test case/ignore next iterations

Posted: Mon Mar 10, 2014 5:03 pm
by odklizec
Hi Robert,

Thanks for the reply and suggestion! Looks workable ;) I'm going to try it in my project.

Anyway, if there is currently not an official way to terminate the Test Case from code, it would be great to have such feature in future Rx versions. Would it be possible to add such feature request to your bug tracking system? Looking at previous forum discussions, I'm sure I'm not alone who needs this option? ;)

Re: How to stop test case/ignore next iterations

Posted: Wed Mar 12, 2014 10:14 am
by Support Team
Hi odklizec,

I’m glad I could help. We will discuss a feature request internally.

Regards,
Robert

Re: How to stop test case/ignore next iterations

Posted: Wed Feb 04, 2015 6:11 pm
by aturner
I was using the above mentioned throw exception method of controlling which test cases ran during a test. Ah it was ugly. Then I found this a forum post titled:

Starting Testcase by condition
(Can't post url as new user)

Now I run a test module selection code module first, it checks my data for what tests need to be run and sets the checkmarks for test cases. Much cleaner.

Re: How to stop test case/ignore next iterations

Posted: Thu Feb 05, 2015 6:20 pm
by Support Team
Hi aturner,

You meant this post: http://www.ranorex.com/forum/starting-t ... t3899.html, right?
So everything is working, or do you have any questions?

Regards,
Markus

Re: How to stop test case/ignore next iterations

Posted: Wed Jul 13, 2016 3:46 pm
by stapes
This has changed since Ranorex 6.

This does the trick:

Code: Select all

var tc1=(TestCaseNode) TestCaseNode.Current ;
        	
        	foreach(TestModuleLeaf a in tc1.AllModules)  
            {  
                a.Enabled = false;  
                Report.Info("TestModuleLeaf disable."+a.Name);
            }