How to put conditional statements in *.cs file of recording

Ranorex Studio, Spy, Recorder, and Driver.
Amit_Malviya
Posts: 7
Joined: Fri Jun 06, 2014 9:47 am

How to put conditional statements in *.cs file of recording

Post by Amit_Malviya » Fri Jun 06, 2014 1:49 pm

Hi All,

I am using 1 month trial version of ranorex for POC. I am very new to this tool.I have created one test case by adding multiple recording.

I want to implement conditional execution of steps withing recording. Like if my first action (given in user code) is passed than only following steps should execute or else not.

Scenario Is:
my application has a form to create a new program details under program management module. I want to fill complete details in 'add new program form' if my certain field on 'Add new program Form' is enable.

Can anyone please help me on this?



Thanks
Amit

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How to put conditional statements in *.cs file of recording

Post by krstcs » Fri Jun 06, 2014 2:57 pm

Ranorex has 3 files associated with a recording module.
1. *.rxrec (i.e., Recording1.rxrec) - This is an XML file that is the basis for the action table in the recording module in Ranorex Studio. It is generated by Ranorex and should not be modified manually.
2. *.cs (i.e., Recording1.cs) - This is the "backing" file for the recording and is what .NET actually uses to compile the test. It is machine generated and should not be modified manually.
3. *.UserCode.cs (i.e., Recording1.UserCode.cs) - This is the place for any custom user code and will not be changed by Ranorex (except for inserts when needed).

The *.cs file is generated by Ranorex and cannot be edited as all edits will be lost.

If you want to add code to a recording module, you should add a "User Code" action to the action table and create a method in the *.UserCode.cs file that will be called.
Shortcuts usually aren't...

Amit_Malviya
Posts: 7
Joined: Fri Jun 06, 2014 9:47 am

Re: How to put conditional statements in *.cs file of recording

Post by Amit_Malviya » Fri Jun 06, 2014 4:06 pm

Hi krstcs,

thanks for information. I started using right approach. thanks.

second part of my question was "can i execute recording actions on conditional basies ?" (without converting recording into usercode).

For example:
If my validation in recording is passed successfully , only than my remaining/ following actions should be execute or else it should not be execute.

something like , if - else block, but though recording.

Thanks
Amit

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How to put conditional statements in *.cs file of recording

Post by krstcs » Fri Jun 06, 2014 5:32 pm

There is no way to build logic into the module without converting it to user code.


For the test suite, you could consider each test case to be a for-each-loop that loops once for each row in the data source. This can be used as a sort of logic gate if done correctly, but it is complicated and I would not recommend it for people new to Ranorex, test automation, or databases. It involves heavy use of SQL Server database and lots of queries and much more user code.


Ranorex has held the position that the test should be small and contain no logic. I would tend to agree with this in most cases. Adding logic to the test cases/recording modules tends to obfuscate the true goal of the test leading to confusion and misunderstandings. It also tends to make the tests overly complicated.

There are situations, especially when you get in to VERY advanced automation, where you might want to have logic, but it should be considered very carefully, and, again, it isn't something I would recommend to the novice.
Shortcuts usually aren't...

Amit_Malviya
Posts: 7
Joined: Fri Jun 06, 2014 9:47 am

Re: How to put conditional statements in *.cs file of recording

Post by Amit_Malviya » Wed Jun 11, 2014 7:18 am

Thanks krstc :).

You made it clear to me.