Page 1 of 1

how to use a string from one module to other module

Posted: Mon Nov 02, 2015 3:29 pm
by ejji09
Hi,

Am using user code module with repositories and in my test suite i have five test cases and each test case has one user code module

Am using a string ts as timestamp for a filename of the txt file(which contains time taken to execute the certain step in my application) and i want to use the same string in the other code module as the same timestamp. How is it possible.

String ts= System.DateTime.Now.ToString("ddMMyyyyhhmmss");

System.IO.File.AppendAllText(@"C:\\save\\"+ts+.txt"+"DateTime: ",dt+Environment.NewLine+"TestCase: "+TestCase.Current.Name+Environment.NewLine+"Duration: "+s+Environment.NewLine);

Thank you.

Re: how to use a string from one module to other module

Posted: Mon Nov 02, 2015 3:32 pm
by odklizec
Hi,

This blog post should help you...
http://www.ranorex.com/blog/sharing-dat ... to-another

Re: how to use a string from one module to other module

Posted: Mon Nov 02, 2015 4:00 pm
by ejji09
But how to call the below string

String ts= System.DateTime.Now.ToString("ddMMyyyyhhmmss");

In the other code module from the first code module.

Re: how to use a string from one module to other module

Posted: Mon Nov 02, 2015 4:45 pm
by odklizec
Hi,

The article I suggested in previous post describes sharing values between modules. So it should be exactly what you are looking for? If you have a problem with exact C# code, then you can use Recording module and examine the code behind the individual actions (right click on an action and select View Code or use Ctrl + Enter shortcut).

Basically, if you don't want to use variable binding, you can use below code to save string to TC parameter:

Code: Select all

String ts= System.DateTime.Now.ToString("ddMMyyyyhhmmss");
TestCase.Current.Parameters["timeStamp"]= ts;
And this is how you can retrieve the string from parameter in another module...

Code: Select all

string ts = TestCase.Current.Parameters["timeStamp"];