Launch a recording from a UserCode script (resolved)

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

Launch a recording from a UserCode script (resolved)

Post by romainb25 » Wed May 25, 2016 8:51 am

Hi community,

I have a little trouble.
I have two recordings. Each recording is linked to excel data tests by an Excel Data Connector
In each recording, i have a usercode.cs file
In recording 1, i try to launch recording 2 with this command:
Recording2.Start();
It run the recording2 but data tests are not called.

See picture below for description
Dessin sans titre.png
Can i call a recording with his data tests?
Can i call directly a Code Module from an other Code Module?

Thanks
Romainb25
You do not have the required permissions to view the files attached to this post.
Last edited by romainb25 on Thu Jun 16, 2016 11:32 am, 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: Launch a recording with data test from a UserCode script

Post by odklizec » Wed May 25, 2016 12:09 pm

Hi,

If you call a Recording module directly from code, it's definitely not attached to data connector anymore. What you call is in fact another instance of Recording module and not the one stored in TestCase, which is connected to data connector.

I would definitely suggest not to call recording/code modules from other modules, because this could cause a mess and broken test workflow. Could you please elaborate why do you want to use this approach? I think there is always a way to achieve what you want by using standard test suite workflow and maybe some custom code, to enable/disable certains test cases in runtime.
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

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

Re: Launch a recording with data test from a UserCode script

Post by romainb25 » Wed May 25, 2016 1:18 pm

i have to test a print folder management software
There are 4 steps to create a print folder:
- Create a folder with some information
- Create a print subfolder
- Create a pinout subfolder
- Create a routing folder

For each step, i create a recording
Each recording is linked to an excel data test
The thing is when i want to create a print subfolder, i have before to create a folder, so if i want to create 4 subfolder, i have to create 4 folders.
For example, in my print subfolder usercode.cs:
CreateFolder.Start(); //call CreateFolder recording

Is there other ways to call recordings like this?

Am i clear? (not easy to explain in English :D )

Thanks
Romainb25

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

Re: Launch a recording with data test from a UserCode script

Post by Support Team » Fri May 27, 2016 1:24 pm

Hello Romainb25,

This is exactly the way in order to start recordings in user code. I'm not exactly sure, do you face any problems when executing the recording using this method?

Regards,
Bernhard

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

Re: Launch a recording with data test from a UserCode script

Post by romainb25 » Mon May 30, 2016 11:15 am

Hi,

With the Recording.Start(); command, it runs the Recording but like odklizec said :
"If you call a Recording module directly from code, it's definitely not attached to data connector anymore"
So i have to found an other way.

Thanks
Romainb25

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

Re: Launch a recording with data test from a UserCode script

Post by Support Team » Thu Jun 02, 2016 3:09 pm

Hello Romainb25,

That's correct. The data connector is bound to a test case and not to the recording directly. That means you have to run the whole test case. In general, we don't recommend starting recordings from user code because of several reasons. Maybe there is a way structuring your test in order to prevent starting recordings from user code.

If you still want to so you have to load the excel data in user code inside the recording directly (for example using the .NET Framework)

I hope I could clarify the situation.

Regards,
Bernhard

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

Re: Launch a recording with data test from a UserCode script

Post by krstcs » Thu Jun 02, 2016 4:16 pm

One thing you could do is add Test Variables to your usercode module (right-click anywhere in the code and select 'Insert New Module Variable'). Then bind those variables in the test case and use them in the code to initialize the other modules' variables.

So, if you add 'Variable1' as a module variable for the usercode module you can add the following code to initialize your called module's variables with the data set you need.

Code: Select all

MyTestModule myModule = new MyTestModule();
myModule.Variable1 = Variable1;
TestModuleRunner.Run(myModule);
You can add as many variables and called modules as you need.

I use this for resetting my SUT since there is no way to do conditional execution of modules in normal Ranorex test cases (but this should be coming in later versions...), which we require for SUT resets when things fail badly in order to continue with the next iteration.

However, as Bernhard said, this is not recommended.
Shortcuts usually aren't...