Page 1 of 1

How to use a variable of a code module to another code modul

Posted: Thu Aug 25, 2016 10:22 am
by ananth.shenoy
I have Created a variable in one code module.Can i use that variable in another code module?If SO how to use

Re: How to use a variable of a code module to another code modul

Posted: Thu Aug 25, 2016 3:51 pm
by krstcs
Please read the user guide, it explains clearly how to handle this situation.

http://www.ranorex.com/support/user-guide-20.html

You probably will need to use a Global or Test Case parameter to hold the value of the variable between module executions. Bind the parameter to the variables in each module.

Re: How to use a variable of a code module to another code modul

Posted: Thu Aug 25, 2016 3:57 pm
by N612
First, Declare the variable and make it static: (Right Click in code module > Insert New Module Variable)

Code: Select all

static string _myVar = "testVar";
[TestVariable("0f6808ec-bef9-44de-ae74-2a7de9eb6baf")]
static public string myVar
{
    get { return _myVar; }
    set { _myVar = value; }
}
Now you can use this variable in another code module. There are two ways you can use it:

1. With Inheritance:

Code: Select all

public class CodeMod2 : CodeMod1, ITestModule
myVar = "myVar-Modified";
Note: This will also work without making your variable static but will be its own instance when inherited.

2. Without Inheritance:

Code: Select all

CodeMod1.myVar = "myVar-Modified";