Receive path of Report location by arguments cmd

Ask general questions here.
Enjoy
Posts: 9
Joined: Tue Apr 13, 2010 10:05 am

Receive path of Report location by arguments cmd

Post by Enjoy » Tue May 11, 2010 6:26 pm

Hello ppl

i have my test cases able to run from the command line receveiving 1 argument( txt file with the path of the application to be tested) and i need to receive one more argument, a path like : d:\folder1\fold2\ and i need to receive that and change the Program.cs file to generate the report on that specific folder. I create an extern Library to support Ranorex

I'm using this code on my UserCode(it works very good while launching application to be tested)
private static Dictionary<string, string> config;

public static void Setup(string[] args)
{

if (args.Length > 0)
{
try
{
config = TestUtils.LoadConfiguration(args[0]);
System.Diagnostics.Process.Start(config["exe"]);
}
catch (Exception e)
{
Report.Error("Unexpected exception occured:" + e.ToString());
}
}
Can you help me?

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Receive path of Report location by arguments cmd

Post by Ciege » Tue May 11, 2010 9:54 pm

Is this what you are looking for for setting the log file location?
http://www.ranorex.com/forum/execution- ... t1363.html

You can then use args[1] to get the next command line argument or use a foreach statement to loop through any and all argumnets.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Receive path of Report location by arguments cmd

Post by Support Team » Wed May 12, 2010 8:28 am

As Ciege said, args is a string array, holding as many entries as you specifed arguments on the command line. Thus you can loop through the entries (foreach statement) and add it to your config dictionary inside your LoadConfiguration method - or just use the second entry (args[1]) for the repport file path.

For an example on how to use command line parameters see following blog:
http://www.ranorex.com/blog/defining-ex ... ur-ui-test

Regards,
Alex
Ranorex Support Team

Enjoy
Posts: 9
Joined: Tue Apr 13, 2010 10:05 am

Re: Receive path of Report location by arguments cmd

Post by Enjoy » Wed May 12, 2010 5:20 pm

At this moment i'm using that code on testcase/UserCode :
if (args.Length > 0)
{
System.Console.WriteLine("Number of command line parameters = {0}", args.Length);
foreach (string arguments in args)
{
System.Console.WriteLine(arguments);
}
and when i run the test only receive 1 argument and i'm using this code in my .Net console application:

System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = archive;
process.StartInfo.Arguments = configpath;
process.StartInfo.Arguments = reportdir;
process.EnableRaisingEvents = true;
process.Start();
If i comment the line where i pass the reportdir the test runs normaly but i need to pass that argument...How can i do that and pass reportdir to Program.cs where i have:

string logFileName = config["reportdir"] + "\testxx.rxlog";
Report.Setup(ReportLevel.Debug, logFileName, true);

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Receive path of Report location by arguments cmd

Post by Ciege » Wed May 12, 2010 5:58 pm

It would seem that you are overwriting your arguments using your code.

Code: Select all

process.StartInfo.Arguments = configpath;
process.StartInfo.Arguments = reportdir;
You should either put all the aguments you want on the same arguments line:

Code: Select all

process.StartInfo.Arguments = configpath + " " + reportdir;
Or use the Arguments.Insert method to add multiple arguments to your startinfo.

Code: Select all

process.StartInfo.Arguments.Insert(0,configpath);
process.StartInfo.Arguments.Insert(1,reportdir);
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Receive path of Report location by arguments cmd

Post by Support Team » Wed May 12, 2010 6:03 pm

Ciege wrote:Or use the Arguments.Insert method to add multiple arguments to your startinfo.
I don't think that this will work, cause the Arguments.Insert method is just the normal string.Insert method. Please, concatenate multiple arguments manually separated by blanks.

Regards,
Alex
Ranorex Support Team

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Receive path of Report location by arguments cmd

Post by Ciege » Wed May 12, 2010 6:26 pm

I guess you are right. Not sure why I thought the Arguments.Insert method would work. I thought I read about that once long ago while learning c# but alas, I cannot get it to work.

As Alex said, use multiple arguments on the same arguments line concatenated by spaces.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

Enjoy
Posts: 9
Joined: Tue Apr 13, 2010 10:05 am

Re: Receive path of Report location by arguments cmd

Post by Enjoy » Thu May 13, 2010 9:36 am

Thanks to Ciege and all the Support Team, that works ;)