Determine test case execution based on variable?

Ask general questions here.
User avatar
Gunner1980
Posts: 89
Joined: Mon Apr 05, 2010 8:44 pm
Location: Austin, Texas

Determine test case execution based on variable?

Post by Gunner1980 » Tue Apr 05, 2011 6:58 pm

So I have various setup scripts and I want to be able to specify whether or not I want to setup a simulator as well via a variable I have called SIM.

My test case normally runs as follows

Configure
Setup
DisplaySetup

if I have set a simulator I want the following to run

Configure
Setup
DisplaySetupWithSimulator

So basically I need a way in the test suite to specify which recording module to run based on this SIM variable. If it is false I want to run DisplaySetup and if it is true I want it to run DisplaySetupWithSimulator.

I had this working in 2.3.8 with user code but I also need to pass the recording variables from a CSV file and don't know how well this will work in 3.0 if I leave it all in the user code and don't put the recording into the test suite.

So basically is there anyway to have one test case or another called by setting a variable?

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Determine test case execution based on variable?

Post by Support Team » Wed Apr 06, 2011 11:25 am

Hi,

you still have to do it in user code.
Just generate a new user code module, insert a new module variable to your user code module and bind the wanted variable to this module variable.

Have a look at following chapter in user guide:
http://www.ranorex.com/support/user-gui ... html#c3112

Now you can start depending on the module variable either "DisplaySetupWithSimulator" or "DisplaySetup" using a simple if statement on your module variable.

Regards,
Tobias
Support Team

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Determine test case execution based on variable?

Post by Support Team » Thu Apr 07, 2011 5:46 pm

Hello,

here is the sample code, that shows how you can use the variables of recordings called from user code. "SIM" is the variable deciding whether to start Recording1 or Recording2. All variables you need from Recording1 or Recording2 have to be "forwarded" to the User Code module, see variable "rec1var":
bool _SIM;
        [TestVariable("91335C0C-5679-4246-8D9F-1E75704B84A3")]
        public bool SIM
        {
        	get { return _SIM; }
        	set { _SIM = value; }
        }
        
        [TestVariable("EA684750-8C78-4584-ABE5-558B1B0866E1")]
        public string rec1var
        {
        	get { return Recording1.Instance.rec1var; }
        	set { Recording1.Instance.rec1var = value; }
        }
        void ITestModule.Run()
        {
            Mouse.DefaultMoveTime = 300;
            Keyboard.DefaultKeyPressTime = 100;
            Delay.SpeedFactor = 1.0;
            
            if (SIM)
            {
            	Recording1.Start();
            }
            else
            {
            	Recording2.Start();
            }
        }
Regards,
Roland
Ranorex Support Team