Page 1 of 1

Skip remaining iteration items without throwing an exception

Posted: Tue Sep 24, 2013 2:16 pm
by kmck
I am running a data driven test that runs through a list of dynamic items that may or may not exist at the time of testing, and I want to validate the data if the item does exist, and just skip to the next iteration if the item does not exist.

I know I can use Validate.Exists() for the repo item and then use the following to skip the rest of the iteration:

Code: Select all

throw new RanorexException();
However I want to just skip the iteration if the item doesn't exist, not throw an exception which results in a failure on the report. Is there currently a way to do this within Ranorex?

Re: Skip remaining iteration items without throwing an exception

Posted: Wed Sep 25, 2013 3:17 pm
by Support Team
Hello,

There is also a method called Validate.NotExists(). You can use the parameter if no exception should be thrown.
Please take a look at the "Online API Documentation" in order to get more information about this method.
There is already a similar post in our forum which could help solving your issue.
Post: How to force a test iteration to skip
Maybe this is what you are searching for.
Please let me know if you need something else.

Regards,
Bernhard

Re: Skip remaining iteration items without throwing an exception

Posted: Wed Sep 25, 2013 10:28 pm
by kmck
Hi Bernhard,

Thank you for your reply. The Exists() method works as needed, but I am having through getting Ranorex to then skip the remaining items in the test case's iteration if the result of my validation is false without producing a failure report.

I have tried implementing the following code in my Program.cs file (as per http://www.ranorex.com/forum/how-to-for ... t3360.html):

Code: Select all

[STAThread]  
        public static int Main(string[] args)  
        {  
            Keyboard.AbortKey = System.Windows.Forms.Keys.Pause;  
            int error = 0;  
  
            TestSuite.TestSuiteCompleted+= new EventHandler(TestSuite_TestSuiteCompleted);  
            try  
            {  
                error = TestSuiteRunner.Run(typeof(Program), Environment.CommandLine);  
            }  
            catch (Exception e)  
            {  
                Report.Error("Unexpected exception occurred: " + e.ToString());  
                error = -1;  
            }  
            return error;  
        }  
  
        static void TestSuite_TestSuiteCompleted(object sender, EventArgs e)  
        {  
          ActivityStack.Instance.VisitAll(a => {  
                                            if (a.CustomProperties.ContainsKey("ignore"))  
                                              a.Status = ActivityStatus.Ignored;  
                                            return true;  
                                          });  
        }  

And then placed this within the test case that runs the iteration:

Code: Select all

if(iteration>yourLimit)  
    ActivityStack.Current.Parent.CustomProperties["ignore"] = "";  
However I am getting an "Object reference not set to an instance of an object" error for that. Is there something I missed in the code?

Re: Skip remaining iteration items without throwing an exception

Posted: Fri Sep 27, 2013 10:01 am
by Support Team
Hello,

I cannot find a fault, in my case the code works.
Could you please check if the variables "iteration" and "yourLimit" are set correctly.
Which version of Ranorex are you using?
Please post the whole error message.
Thank you!

Regards,
Bernhard