Complete stop on fail/error

Ask general questions here.
cpalex
Posts: 20
Joined: Sat Feb 17, 2018 12:37 am

Complete stop on fail/error

Post by cpalex » Mon Apr 01, 2019 10:16 pm

I have been searching, but all I can find is how to report failures...

I just need the code to completely stop all execution if a condition is met.... Do not pass go, do not tear down, just stop.

I have a restore function, that if it fails, is closing the application via the teardown, which leaves a backup process running. I want to just stop everything, report back the error, and let a person re-stage the system properly before the next run.

Right now, here's a simplified version of my code:

Code: Select all

try{
            Report.Log(ReportLevel.Info, "Wait", "Waiting 30s to exist. Associated repository item: 'rawtextInfo'", rawtextInfo, new ActionTimeout(30000));
            rawtextInfo.WaitForExists(30000);
}
 catch  {
        		throw new Ranorex.RanorexException("Failed to restore backup, exititing test execution");
        	}
But the exception still lets the teardown run, which closes the application.

What code stops the whole thing??

McTurtle
Posts: 227
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Complete stop on fail/error

Post by McTurtle » Tue Apr 02, 2019 7:29 am

Hi cpalex,

You can disable all modules inside teardown sections before throwing the exception by calling this code:
public void DisableTeardownExecution()
		{
			var suite = (TestSuite)TestSuite.Current;
			var entries = suite.GetAllTestSuiteEntries();  
  
            foreach (var entry in entries)  
            {  
                var tc = entry as TearDownNode;  
                if (tc != null)  
                {  
                    var ChildrenOfTeardown=tc.Children;
                    int j=tc.Children.Count;
                    
                    for (int i=0;i<j;i++)
                    {
                    	Report.Info(String.Format("Removing module {0} from teardown of {1}.",tc.Children[0].Name, tc.Parent.Name));
                    	tc.RemoveChild(tc.Children[0]); 
                    }   
                }  
            }  
		}
The same would probably work for disabling any module during runtime. I have not tried... But I did do some testing for disabling everything in teardowns all over the test suite and it seems to work so far.

Regards,
McTurtle

cpalex
Posts: 20
Joined: Sat Feb 17, 2018 12:37 am

Re: Complete stop on fail/error

Post by cpalex » Tue Apr 02, 2019 2:53 pm

Oh man, that will be perfect, thank you! It's only one module that's causing me grief anyway, the one closing the application.