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

Ranorex Studio, Spy, Recorder, and Driver.
agroenen
Posts: 17
Joined: Thu Jun 09, 2016 3:18 pm

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

Post by agroenen » Tue May 30, 2017 2:08 pm

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.
Last edited by agroenen on Tue May 30, 2017 2:24 pm, edited 1 time in total.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

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

Post by odklizec » Tue May 30, 2017 2:24 pm

Hi,

I don't think you can actually disable recording/code module from code. Only TestCases/SmartFolders can be disabled this way.
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

agroenen
Posts: 17
Joined: Thu Jun 09, 2016 3:18 pm

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

Post by agroenen » Tue May 30, 2017 2:40 pm

That would be too bad....
Is there a possibility to stop (without failure!) the current test module, based on validation then?

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

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

Post by Vaughan.Douglas » Tue May 30, 2017 2:56 pm

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.
Doug Vaughan

agroenen
Posts: 17
Joined: Thu Jun 09, 2016 3:18 pm

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

Post by agroenen » Thu Jun 01, 2017 12:50 pm

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.

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

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

Post by Vaughan.Douglas » Thu Jun 01, 2017 1:27 pm

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.
Doug Vaughan