How to stop test case/ignore next iterations

Ask general questions here.
User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7469
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

How to stop test case/ignore next iterations

Post by odklizec » Fri Mar 07, 2014 9:28 am

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.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to stop test case/ignore next iterations

Post by Support Team » Mon Mar 10, 2014 4:35 pm

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

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7469
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to stop test case/ignore next iterations

Post by odklizec » Mon Mar 10, 2014 5:03 pm

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? ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to stop test case/ignore next iterations

Post by Support Team » Wed Mar 12, 2014 10:14 am

Hi odklizec,

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

Regards,
Robert

aturner
Posts: 5
Joined: Wed Oct 01, 2014 5:02 pm

Re: How to stop test case/ignore next iterations

Post by aturner » Wed Feb 04, 2015 6:11 pm

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.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to stop test case/ignore next iterations

Post by Support Team » Thu Feb 05, 2015 6:20 pm

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

stapes
Posts: 206
Joined: Wed Sep 16, 2015 10:55 am

Re: How to stop test case/ignore next iterations

Post by stapes » Wed Jul 13, 2016 3:46 pm

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);
            }