Page 1 of 1

How to change variables in partial class?

Posted: Tue Jul 08, 2014 2:22 pm
by mirih87
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

Re: How to change variables in partial class?

Posted: Tue Jul 08, 2014 5:42 pm
by krstcs
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.