Teardown and continue with iteration

Ask general questions here.
tallahassee101
Posts: 169
Joined: Thu Jan 13, 2011 2:06 pm

Teardown and continue with iteration

Post by tallahassee101 » Wed Oct 10, 2012 2:18 pm

Hi,

I have an iteration of tests I am running that is data driven. We are using the following code to test if the testcase has failed, however once a single iteration fails every iteration thereafter returns a failed value, even though the iteration's tests were successful. I believe this is because TestReport.CurrentTestCaseActivity returns the failure/success of the current test case rather than the current test case's iteration. Is there a way to get the iteration's failure/success value?

Here is the code we are using:

Code: Select all

static class FailedFinder  
        {  
            static public Activity Failed = null;  
            static public void Search(Activity act)  
            {  
                foreach (Activity child in act.Children)    
                {  
                    if (child is TestModuleActivity)  
                    {  
	                    if (child.Status == Ranorex.Core.Reporting.ActivityStatus.Failed)  
	                        Failed = child;    
                    }  
                    else  
                        Search(child);  
                }  
            }             
        }  
   
        //this is a user code method  
        public void TestFail()  
        {  
			Report.Info("Checking if there was an error thrown.");
			FailedFinder.Failed = null;
            FailedFinder.Search(TestReport.CurrentTestCaseActivity);  
            if (FailedFinder.Failed != null)    
            {    
//This is reached on every iteration after an iteration fails including the failed iteration.
// We want just the failed iteration to reach this section.
				Report.Info("Error found.");
            	ErrorHandling();
            }  
        } 

public void ErrorHandling()
{
//do something here if iteration fails.
}

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

Re: Teardown and continue with iteration

Post by Support Team » Thu Oct 11, 2012 3:14 pm

Hello,

You can use the following line to check if the state of the current iteration is 'Success'.
Ranorex.Core.Reporting.ActivityStack.Current.Parent.Parent.Status.Equals(Ranorex.Core.Reporting.ActivityStatus.Success)
Regards,
Bernhard
Ranorex Support Team

tallahassee101
Posts: 169
Joined: Thu Jan 13, 2011 2:06 pm

Re: Teardown and continue with iteration

Post by tallahassee101 » Mon Oct 29, 2012 3:50 pm

So I used that code and now I get an error on every iteration. Am I using the code correctly?

This code always calls error handling regardless of pass/fail of iteration

Code: Select all

          if(!Ranorex.Core.Reporting.ActivityStack.Current.Parent.Parent.Status.Equals(Ranorex.Core.Reporting.ActivityStatus.Success))    
            {    
		Report.Info("Error found.");
            	ErrorHandling();
            }  
While this code never calls errorhandling regardless of pass/fail.

Code: Select all

          if(Ranorex.Core.Reporting.ActivityStack.Current.Parent.Parent.Status.Equals(Ranorex.Core.Reporting.ActivityStatus.Failed))    
            {    
		Report.Info("Error found.");
            	ErrorHandling();
            }  
So I then ran a successful test and put a breakpoint to see the returned values from the calls. All six of the below calls returned False, which shouldn't be possible if this were working properly. Any idea what could be causing this method to not run properly?

Code: Select all


			bool bSelfReturns = Ranorex.Core.Reporting.ActivityStack.Current.Status.Equals(Ranorex.Core.Reporting.ActivityStatus.Failed);
			bool bParentReturns = Ranorex.Core.Reporting.ActivityStack.Current.Parent.Status.Equals(Ranorex.Core.Reporting.ActivityStatus.Failed);
			bool bParentsParentReturns = Ranorex.Core.Reporting.ActivityStack.Current.Parent.Parent.Status.Equals(Ranorex.Core.Reporting.ActivityStatus.Failed);
			
			bool bSelfReturnsSuccess = Ranorex.Core.Reporting.ActivityStack.Current.Status.Equals(Ranorex.Core.Reporting.ActivityStatus.Success);
			bool bParentReturnsSuccess = Ranorex.Core.Reporting.ActivityStack.Current.Parent.Status.Equals(Ranorex.Core.Reporting.ActivityStatus.Success);
			bool bParentsParentReturnsSuccess = Ranorex.Core.Reporting.ActivityStack.Current.Parent.Parent.Status.Equals(Ranorex.Core.Reporting.ActivityStatus.Success);
Printing the status out for these activities shows that it is "Active" for each one.
Thanks

tallahassee101
Posts: 169
Joined: Thu Jan 13, 2011 2:06 pm

Re: Teardown and continue with iteration

Post by tallahassee101 » Tue Oct 30, 2012 1:13 pm

The problem was that I was using Ranorex 3.3.0. I upgraded to 3.3.3 and everything works correctly now with the original code provided.