Tutorial for variables in user code and repository

Class library usage, coding and language questions.
User avatar
iskrenpp
Posts: 11
Joined: Fri Aug 17, 2012 4:36 am

Tutorial for variables in user code and repository

Post by iskrenpp » Fri Aug 17, 2012 4:49 am

Hi support team,
I recently started learning Ranorex test studio and was able to achieve good results. The current problem that I cannot find enough information to overcome is how to create and use variables connected to Dataconnector Excel spreadsheet in user code which are actually part of a repo element.
I have a path that has an element that I would like to make variable and externally load different values for from Excel spreadsheet and at the same time use it in user code.
Example
repo item:
dom[@domain='xxx']/element[@description='yyy']/element[@description='zzz']

I need to have yyy replaced by variable which can be referenced in user code.
i.e.

dom[@domain='xxx']/element[@description='$varName']/element[@description='zzz']

One of your tutorials shows that you can create a setter method by right-click and selecting Insert module variable but I can't seem to find a menu that shows that option.

I can drag and drop a repo element in user code and thus create a declared variable in code - actually not sure if this is what I need.

Bottom line is that I need an example of how to create bridge connector to connect repo variable to external excel spreadsheet in user code. Whatever I seem to try never gives me the option to bind the variable to attached data source. MY programming skills are not very solid but I catch on quickly.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11710
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Tutorial for variables in user code and repository

Post by Support Team » Fri Aug 17, 2012 12:47 pm

Hi,

You just have to click on "VARIABLES..." in your recording, where you want to use the variable, and then you have to click on "Copy Variable from Repository" in the "Edit Variables of Recording" window.
The new created Module Variable can then be bound to a column of your Excel connector.

Regards,
Markus
Ranorex Support Team
.
Image

User avatar
iskrenpp
Posts: 11
Joined: Fri Aug 17, 2012 4:36 am

Re: Tutorial for variables in user code and repository

Post by iskrenpp » Mon Aug 27, 2012 6:06 pm

Thank you for your guidance. I have used your pointers and have solved few of my problems.
Now I need to create a variable in user code and be able to bind it to external data source like simple data connector or spreadsheet.

User avatar
iskrenpp
Posts: 11
Joined: Fri Aug 17, 2012 4:36 am

Re: Tutorial for variables in user code and repository

Post by iskrenpp » Mon Aug 27, 2012 7:20 pm

Actually what I need to do is load a screenshot from external file location and then run a user code for each loaded screenshot. Probably it is very simple and is considered part of programming 101 but could you explain how to access an object of type Bitmap in a different user code module?
My plan is to declare a variable in first user code module which can be bound to data source (simple data connector or spreadsheet), then load the screenshot using variable for file location into a Bitmap object, then run from second user code module a separate iteration set for the loaded screenshot. After that continue loading different screenshots and perform same sets of iterations for them.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11710
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Tutorial for variables in user code and repository

Post by Support Team » Tue Aug 28, 2012 2:02 pm

Hi,

If you want to add a Module Variable to a UserCode Module you have to right click where you want to add the variable to and select "Insert Module Variable".
You can for instance create a static variable to make it accessible from other modules.

Regards,
Markus
Ranorex Support Team
.
Image

User avatar
iskrenpp
Posts: 11
Joined: Fri Aug 17, 2012 4:36 am

Re: Tutorial for variables in user code and repository

Post by iskrenpp » Tue Aug 28, 2012 7:39 pm

I wish it was that easy. I have seen this tutorial many times but was never able to get this option appear. I have right-clicked on all possible locations within a user code module and there is no Insert module variable option that I can click. Any ideas? I still use the trial version bit I don't think this is the issue.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11710
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Tutorial for variables in user code and repository

Post by Support Team » Wed Aug 29, 2012 12:59 pm

Hi,
iskrenpp wrote:I wish it was that easy. I have seen this tutorial many times but was never able to get this option appear. I have right-clicked on all possible locations within a user code module and there is no Insert module variable option that I can click. Any ideas? I still use the trial version bit I don't think this is the issue.
Where do you want to add a module variable?
In a user code module or in a user code file of a recording module?
Basically, the context menu entry "Insert Module Variable" will only appear within user code modules and not within user code files of recording modules (as you can generated variables using the UI within a recording module).

Regards,
Tobias
Ranorex Team
.
Image

User avatar
iskrenpp
Posts: 11
Joined: Fri Aug 17, 2012 4:36 am

Re: Tutorial for variables in user code and repository

Post by iskrenpp » Wed Aug 29, 2012 9:59 pm

I think I got it. I was not aware that you can create User Code modules that are a stand alone unit. I thought that the only way user code can be written is in the user code file of a recording.

What are pros and cons of using recording module with user code in it versus a pure user code module?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11710
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Tutorial for variables in user code and repository

Post by Support Team » Thu Aug 30, 2012 8:50 am

Hi,
iskrenpp wrote:What are pros and cons of using recording module with user code in it versus a pure user code module?
A user code action should be added If you need to implement short, not complex functionality, which can only be achieved by writing code and not be done with Recorder.

If you are going to implement more complex, reusable sequences, it's appropriate to do this using code modules.

Regards,
Tobias
Ranorex Team
.
Image