how to use a string from one module to other module

Ask general questions here.
ejji09
Posts: 54
Joined: Thu Sep 10, 2015 2:48 pm

how to use a string from one module to other module

Post by ejji09 » Mon Nov 02, 2015 3:29 pm

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.

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

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

Post by odklizec » Mon Nov 02, 2015 3:32 pm

Hi,

This blog post should help you...
http://www.ranorex.com/blog/sharing-dat ... to-another
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

ejji09
Posts: 54
Joined: Thu Sep 10, 2015 2:48 pm

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

Post by ejji09 » Mon Nov 02, 2015 4:00 pm

But how to call the below string

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

In the other code module from the first code module.

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

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

Post by odklizec » Mon Nov 02, 2015 4:45 pm

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"];
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