IF statement as Recording actions?

Ranorex Studio, Spy, Recorder, and Driver.
romainb25
Posts: 15
Joined: Mon May 09, 2016 2:31 pm

IF statement as Recording actions?

Post by romainb25 » Fri May 20, 2016 10:36 am

Hi community,

I have two test cases in Ranorex:

-TC1: Create a non-professional account with a form
RunApplication
Click Login
KeySequence $login
Click Password
KeySequence $password

-TC2: Create a professional account with a form
RunApplication
Click Login
KeySequence $login
Click Password
KeySequence $password
click Company
KeySequence $company

There is just an aditionnal variable in the second test case.
My variables are in an Excel file which is connected to test cases with an Excel Data Connector.
This is my Excel file:

------------------------------------------------
Type | Login | Password | Company
pro | ad1 | mp1 | google
nopro| ad2 | mp2 |
------------------------------------------------

I would like to make one test with the two test cases.
If i have nopro as type in Excel file, run actions
If i have pro as type in Excel file, run different actions

It is possible to make an if statement as Recording actions in Ranorex?

Thanks
Romainb25

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

Re: IF statement as Recording actions?

Post by odklizec » Fri May 20, 2016 11:02 am

Hi,

At the moment, the only way how to add conditional running of steps within Recording module, is to convert the steps into user code and then add some conditions in code.

Another approach would be to create multiple TCs and run enable/disable them via code module placed before first (each) TC and using code described here:
http://www.ranorex.com/forum/data-bindi ... tml#p37602
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

zivshapirawork
Posts: 65
Joined: Wed Sep 24, 2014 7:47 am
Location: Israel

Re: IF statement as Recording actions?

Post by zivshapirawork » Mon May 23, 2016 6:11 am

Hi

you might drop the pro/nonpro and just always click company and then enter the value in the Excel. just for nonpro it is an empty string, so Ranorex will not type anything in company, which is the same as a nonpro user would do.

sistinus
Certified Professional
Certified Professional
Posts: 4
Joined: Mon Dec 02, 2013 2:51 pm

Re: IF statement as Recording actions?

Post by sistinus » Mon May 23, 2016 12:54 pm

We heavily use optional variables in user code to make our modules more versatile. We'll make an optional action for each field on a form so actions for the entire form only needs to be created once. It just looks to see if a variable has a value and if so it does the action, if not it skips that field. This is what it looks like:

Code: Select all

        	if (!string.IsNullOrEmpty(varCompany))
        	{
	            repo.Company.Click();
	            repo.Company.PressKeys(varCompany);
        	}
If you're going to use this frequently as we do, you may want to add report.info for your actions so they show up on your report and in case of a failure you can see where it went wrong. For text fields we'll also usually set the value to blank as the first action to make sure there isn't already text in the field.

Hope this helps.

romainb25
Posts: 15
Joined: Mon May 09, 2016 2:31 pm

Re: IF statement as Recording actions?

Post by romainb25 » Tue May 24, 2016 11:30 am

It works, thank you everibody!