Stop running module on condition

Best practices, code snippets for common functionality, examples, and guidelines.
User avatar
Ranorex Guru
Ranorex Guru
Posts: 7465
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Stop running module on condition

Post by odklizec » Wed Sep 20, 2017 7:50 am


I don't think there is a safe way to kill the module at start (in the middle) of execution and then continue with other modules in setup/teardown or even testcase/smartfolder.

What you can do is to add a code module to setup/teardown section (as a very first module in section), in which you evaluate your condition and eventually disable all modules in given section. The code to disable all modules in setup section should look like this:

Code: Select all

	var curTestCase = (TestCaseNode)TestSuite.CurrentTestContainer;  
	//your condition
	if (iObject.Exists(1000))
		foreach(TestModuleLeaf module in curTestCase.AllModules)  
			if (module.IsDescendantOfSetupNode())
				module.Enabled = false;  
Of course, if your test case runs multiple times, you must re-enable the setup section modules, otherwise, they will stay disabled during the next iteration ;) So you simply need to run the above code (best in teardown section) with module.Enabled = true;.
Hope this helps?
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