Recording v code modules

Best practices, code snippets for common functionality, examples, and guidelines.
armstronghm24
Posts: 38
Joined: Tue Dec 20, 2016 10:16 pm

Recording v code modules

Post by armstronghm24 » Thu Jul 13, 2017 2:37 pm

Hi,

Is there a good rule of thumb versus when to use a recording module versus when to use a code module? Are there features that can be used when using recording modules that won't work when using code modules?

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

Re: Recording v code modules

Post by krstcs » Thu Jul 13, 2017 2:48 pm

Recording modules are just a pretty view of a code module anyway, so anything you can do in a Recording Module you can do in a code module. Also, you can always just make everything a recording module and then create usercode methods in the recording's usercode file that you call from the recording module's action table.

I would say that the rule of thumb is: If you CAN'T do it in a recording module, do it in a code module (or at least move that part of the recording into the usercode part).

For example, these things are just a few that would need to be done in code:

- Conditionals (if, while, select-case, etc.)

- Reformatting a value before validation or use

- Looping over something that can't be done with a data source

- Generating a value (such as a random name, etc.)

- Any interactions with service level APIs, etc.
Shortcuts usually aren't...

armstronghm24
Posts: 38
Joined: Tue Dec 20, 2016 10:16 pm

Re: Recording v code modules

Post by armstronghm24 » Thu Jul 20, 2017 8:39 pm

Thank you for your response.

There is a central testing team in my organization that has converted some scripts to entirely code modules although there aren't any complex test cases currently in the script that can't be done using the recording module. There are multiple teams that use and will need to modify the script though and I am trying to convince them that the recording modules are the way to go in our case. I'm having trouble getting that message through. Any additional thoughts are appreciated :)

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

Re: Recording v code modules

Post by krstcs » Thu Jul 20, 2017 9:07 pm

Well, in that case, I think the inverse of my rule of thumb is also true.

If you CAN do it in a recording module you SHOULD. It's the easiest way to create scripts and is much easier to maintain than code. It can also be easily understood by almost anyone.

One thing I would recommend though is to keep all of your modules as small as possible. This makes it even easier to maintain them, regardless of it being a recording module or code.

Maybe my earlier rule of thumb should have been: Only use code if you can't do what you need in a Recording module.

I think your peers are needlessly complicating future maintenance and it will come back to bite them or future users. Remember the old coding adage, look at your code as if you were trying to understand it 10 years from now.

But that's all just my opinion.
Shortcuts usually aren't...