Receive path of Report location by arguments cmd : General Questions

Receive path of Report location by arguments cmd

Ask general questions here.

Receive path of Report location by arguments cmd

Postby Enjoy » Tue May 11, 2010 7: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?
Enjoy
 
Posts: 9
Joined: Tue Apr 13, 2010 11:05 am

Re: Receive path of Report location by arguments cmd

Postby Ciege » Tue May 11, 2010 10:54 pm

Is this what you are looking for for setting the log file location?
http://www.ranorex.com/forum/execution-report-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
Ciege
 
Posts: 965
Joined: Thu Oct 16, 2008 7:46 pm
Location: Arizona, USA

Re: Receive path of Report location by arguments cmd

Postby Support Team » Wed May 12, 2010 9: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
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: Receive path of Report location by arguments cmd

Postby Enjoy » Wed May 12, 2010 6: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);
Enjoy
 
Posts: 9
Joined: Tue Apr 13, 2010 11:05 am

Re: Receive path of Report location by arguments cmd

Postby Ciege » Wed May 12, 2010 6: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
Ciege
 
Posts: 965
Joined: Thu Oct 16, 2008 7:46 pm
Location: Arizona, USA

Re: Receive path of Report location by arguments cmd

Postby Support Team » Wed May 12, 2010 7: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
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: Receive path of Report location by arguments cmd

Postby Ciege » Wed May 12, 2010 7: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...
User avatar
Ciege
 
Posts: 965
Joined: Thu Oct 16, 2008 7:46 pm
Location: Arizona, USA

Re: Receive path of Report location by arguments cmd

Postby Enjoy » Thu May 13, 2010 10:36 am

Thanks to Ciege and all the Support Team, that works ;)
Enjoy
 
Posts: 9
Joined: Tue Apr 13, 2010 11:05 am


Return to General Questions

Who is online

Users browsing this forum: No registered users and 0 guests