Make var declared in User Code accessible to parameters?

Class library usage, coding and language questions.
kmck
Certified Professional
Certified Professional
Posts: 83
Joined: Fri Jul 12, 2013 2:41 pm

Make var declared in User Code accessible to parameters?

Post by kmck » Mon Aug 12, 2013 1:51 pm

I am trying to get an int variable declared within a user code action (not module) to be accessible for parameter binding so I can access that variable's value in another recording.

I was able to do this for a new code module by declaring the variable in the constructor, but since the user code actions use partial classes, I am not sure how I would be able to get a variable created within that user code action to be accessible by other recordings.

I have attempted to include the following in the partial class:

Code: Select all

public partial class ChangeSortOrder
{
    public int newSortOrder {
            get { return newSortOrder; }
            set{ newSortOrder = value; }
}
But when I try to bind it to a parameter, it doesn't show in the dropdown list of module variables.

Any way that I can achieve this?

kmck
Certified Professional
Certified Professional
Posts: 83
Joined: Fri Jul 12, 2013 2:41 pm

Re: Make var declared in User Code accessible to parameters?

Post by kmck » Tue Aug 13, 2013 3:25 pm

Have I stumped everyone? :lol:

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Make var declared in User Code accessible to parameters?

Post by odklizec » Tue Aug 13, 2013 4:37 pm

Hi,

I think the problem is in the fact that User Codes currently accept only string parameters...
http://www.ranorex.com/forum/missing-me ... tml#p20338

Hope this helps? ;)
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

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

Re: Make var declared in User Code accessible to parameters?

Post by Support Team » Tue Aug 13, 2013 8:32 pm

kmck wrote:Any way that I can achieve this?
You just need to add the TestVariable attribute to the property with a unique ID as parameter. In user code modules you can also right click in the code editor and select "Insert Module Variable" (see the associated documentation:
string _UserCodeVar = "value";
[TestVariable("90BF060B-6939-4FD4-AD41-C34DECB49DE0")]
public string UserCodeVar
{
    get { return _UserCodeVar; }
    set { _UserCodeVar = value; }
}
Regards,
Alex
Ranorex Team
.
Image