Page 1 of 1

How to enable/disable test module (recording or code)

Posted: Tue May 30, 2017 2:08 pm
by agroenen
I'd like, depending on a condition in a code module, to enable or disable a test module in another test case (but in the same test suite).

This is what I get so far:

Code: Select all

public static void ValidateSkip(Ranorex.Core.Repository.RepoItemInfo K2WItem, string Modulenaam)
        {
        	if(K2WItem.Exists(new Duration(1000)))
			{  
    			Report.Info(K2WItem +" already exists");  
			}  
			else  
			{  
    			Report.Info(K2WItem +" doesn't exist, disable module" + Modulenaam);  
		   	TestSuite.Current.GetTestContainer(Modulenaam).Checked = false;
		   }
      	       
        }
It leads to an error: "object reference not set to an instance of an object", no further information in stacktrace.

I hope that someone can help me fix this, can't find much information about enabeling /disabeling test modules by code.

Re: How to enable/disable test module (recording or code)

Posted: Tue May 30, 2017 2:24 pm
by odklizec
Hi,

I don't think you can actually disable recording/code module from code. Only TestCases/SmartFolders can be disabled this way.

Re: How to enable/disable test module (recording or code)

Posted: Tue May 30, 2017 2:40 pm
by agroenen
That would be too bad....
Is there a possibility to stop (without failure!) the current test module, based on validation then?

Re: How to enable/disable test module (recording or code)

Posted: Tue May 30, 2017 2:56 pm
by Vaughan.Douglas
As far as I understand odklizec is absolutely correct. This one is near and dear to my heart. Then you're going to want to know how to update result for those skipped tests.



Keep in mind, these are all in the same Test Suite, just different test cases. And now that you can't nest Test Cases anymore, you're doing to just use smart folders. I have not dug into the API to see what's specifically changed in the linked examples, but I don't see why you couldn't just add a Smart Folder with a single recorded module that gets checked or unchecked based on your context.

To stop a test case without failure, you could leverage a tryfindsingle and set the optional parameter for throwing an exception to false. So if you found your object and thus want to stop execution, you'd go through the uncheck rigmarole and if you don't find the object you'd go through the check rigmarole.

Re: How to enable/disable test module (recording or code)

Posted: Thu Jun 01, 2017 12:50 pm
by agroenen
Thank you for your clear answer!

This is the end result (if K2WItem exists go on, else disable Testcasenaam), and it works great:

Code: Select all

public static void ValidateSkip(Ranorex.Core.Repository.RepoItemInfo K2WItem, string Testcasenaam)
{
       if(K2WItem.Exists(new Duration(1000)))
       {  
            Report.Info(K2WItem +" bestaat nog niet, " + Testcasenaam + " wordt niet disabled");  
       }  
       else  
        {  
             Report.Info(K2WItem +" bestaat al, " + Testcasenaam + " wordt disabled om diplicaten te voorkomen");  
             TestSuite.Current.GetTestContainer(Testcasenaam).Checked = false;
        }

Still trying to find out though the difference between a smart folder and a test case; is that only the nesting-thing? Binding and number of iterations are able by both.

Re: How to enable/disable test module (recording or code)

Posted: Thu Jun 01, 2017 1:27 pm
by Vaughan.Douglas
agroenen wrote:Still trying to find out though the difference between a smart folder and a test case; is that only the nesting-thing? Binding and number of iterations are able by both.
Smart Folders are a new addition with Ranorex 7.x and frankly I think a lot of us are still trying to figure them out. In older versions of Ranorex you could nest Test Cases directly within Test Cases. This caused a lot of confusion for my teams because each test case would get a discrete pass/fail so if I had one test case with 4 nested test cases and 3 of those four passed I'd get 3 passes and 2 failures reported. That parent Test Case would be considered as "Fail" since one of the child test cases failed.

You used to be able to use "folders" to organize your test cases, but you couldn't bind folders to data sources. Smart Folders are basically a half-way between a Test Case and a Folder. It's a fair solution and does go a long way to clarifying reports for those not as familiar with Ranorex (i.e. management).

Just keep in mind, this method is at a fairly high risk for problems down the road. The folks over at Ranorex have been known to change the underlying objects.