How to change variables in partial class?

Ask general questions here.
mirih87
Posts: 11
Joined: Tue Jul 08, 2014 1:54 pm

How to change variables in partial class?

Post by mirih87 » Tue Jul 08, 2014 2:22 pm

I have 2 variables :$username and $password .
Here is the following code: (automatically generated by RANOREX and can not be changed)
string _userName;

public LogIn()
{
userName = "admin";
Password = "{LShiftKey down}A{LShiftKey up}dmin";
}

/// <summary>
/// Gets or sets the value of variable userName.
/// </summary>
[TestVariable("46a6ece3-889e-450c-b79e-1f8d3d140961")]
public string userName
{
get { return _userName; }
set { _userName = value; }
}

string _Password;

/// <summary>
/// Gets or sets the value of variable Password.
/// </summary>
[TestVariable("36b9e059-2ebd-4bcb-b6fd-d749ed605c7a")]
public string Password
{
get { return _Password; }
set { _Password = value; }
}

The problem is that I want to change the value for those variables. (i want a random value)
How can i do it ?
If i create a new partial class, i can not change the properties for those variables.

Thank u for your help

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

Re: How to change variables in partial class?

Post by krstcs » Tue Jul 08, 2014 5:42 pm

If you need to permanently change them, it is better to set a default value in the Recording Module Variables dialog.

If you need to do it programmatically, you can change them in the "Init()" method in the *.UserCode.cs file. This method gets called before anything else in each module. Just do a standard assignment operation.

Code: Select all

MyVariable = "New Value";
All module variables in Ranorex are "string" types, so you must pass a string value.
Shortcuts usually aren't...