Stop All Test Execution through c#

Ask general questions here.
MatthewBrown
Posts: 5
Joined: Mon Feb 05, 2018 4:51 pm

Stop All Test Execution through c#

Post by MatthewBrown » Wed Apr 18, 2018 1:34 pm

Hello All,
In my tests I have a popup watcher that watches for a 500 server error. (this much is working fine) I know how to cause a single test to fail, but I want to stop all test execution. I would prefer to still run teardown functions, but it's ok if it just quits the test execution completely. Is this possible? I have seen several threads about stopping just the current iteration, or current test case/module, but I have yet to find how to stop the entire test suite.
Thanks in advance.

MatthewBrown
Posts: 5
Joined: Mon Feb 05, 2018 4:51 pm

Re: Stop All Test Execution through c#

Post by MatthewBrown » Wed Apr 18, 2018 4:24 pm

I found something similar for a test case, but have yet to be able to get it working with a test suite. I'm sure it's just something simple that I'm missing. thoughts? here is the code for a test case.
var testcase = (TestCase)TestCase.Current;

foreach(TestSuiteModule a in testcase.AllModules)
{
a.Enabled = false;
}

I found the code snippet at the following location.
https://www.ranorex.com/forum/how-to-st ... tml#p24582

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Stop All Test Execution through c#

Post by Support Team » Fri Apr 20, 2018 2:43 pm

Hello Matthew,

May I ask you to get in touch with our support team. We might have a workaround for your issue. This workaround is using API calls, which are not and should not be public.
Online Support Query: https://www.ranorex.com/support-query/
Thank you for your understanding.

Regards,
Bernhard
.
Image

Vaughan.Douglas
Posts: 250
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Re: Stop All Test Execution through c#

Post by Vaughan.Douglas » Mon Apr 23, 2018 12:47 pm

The easiest way to accomplish this (and avoiding those maintenance prone non-public APIs) would be to simply set a condition that will block execution.

step one: Create a global parameter and give it a value of True or 1 or whatever floats your boat.
step two: Add a rule to all test cases that says only run when <Your Global Parameter> = <The value you set as default>
step three: when a failure condition arises, update that global variable to something other than <The value you set as default>

Depending on your specific implementation, you may have to use this in combination with one of those other methods for stopping the current module/iteration.
Also that snippet

Code: Select all

foreach(TestSuiteModule a in testcase.AllModules) 
{ 
a.Enabled = false; 
} 
Is what I used to use before Ranorex added conditional execution, although I believe the syntax has since changed.
Doug Vaughan

MatthewBrown
Posts: 5
Joined: Mon Feb 05, 2018 4:51 pm

Re: Stop All Test Execution through c#

Post by MatthewBrown » Fri Apr 27, 2018 6:35 pm

Thank you both for the response, I did contact support, and received an api option, but after looking at both options decided to go with the one proposed by Vaughan.Douglas. it does not stop the test immediately, but I did that by adding in a Ranorex exception after updating the global parameter. Below is the code I used.

//Set global parameter to true
TestSuite.Current.Parameters["VAR_CriticalError"] = true.ToString();
//Throw an exception, stopping the current test execution.
throw new RankException("CRITICAL ERROR");

I then added a condition to each test case to check on the global parameter.

Thanks to both Ranorex support and Vaughan.Douglas for the quick responses and excellent solutions.