Page 1 of 1

Launch a recording from a UserCode script (resolved)

Posted: Wed May 25, 2016 8:51 am
by romainb25
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

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

Posted: Wed May 25, 2016 12:09 pm
by odklizec
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.

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

Posted: Wed May 25, 2016 1:18 pm
by romainb25
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

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

Posted: Fri May 27, 2016 1:24 pm
by Support Team
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

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

Posted: Mon May 30, 2016 11:15 am
by romainb25
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

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

Posted: Thu Jun 02, 2016 3:09 pm
by Support Team
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

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

Posted: Thu Jun 02, 2016 4:16 pm
by krstcs
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.