Run multiple projects through powershell

Best practices, code snippets for common functionality, examples, and guidelines.
barkha
Posts: 18
Joined: Tue May 16, 2017 9:41 pm
Location: Ames, IA
Contact:

Run multiple projects through powershell

Post by barkha » Mon Jan 22, 2018 7:14 pm

Greetings.
I have created multiple Ranorex projects that cover different parts of our software. I would now like to run all projects sequentially using powershell whenever there is a new version. However, I am new to powershell and do not have a lot of experience. I want to know if someone has ever tried it before. Is there a way to tell powershell about test statistics ? will we have to go through all the reports manually.

McTurtle
Posts: 297
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Run multiple projects through powershell

Post by McTurtle » Tue Jan 23, 2018 2:44 pm

Hello barkha,

PowerShell can pick up the exit codes of applications. "0" means that the test was successful. "-1" would mean that the test has failed. You would then have to check all the reports for the tests where the exit code was not "0".

Furthermore, PowerShell can also wait for the application to exit before starting a new one.

The following example would start one test, then give you the information if the test has exited and than tell you the exit code of the test. After that, it would do the same for the 2nd test:

$process = Start-Process "C:\Users\username\Documents\Ranorex\RanorexStudio Projects\xxx\bin\Debug\xxx.exe" -NoNewWindow -Wait -PassThru
$process.HasExited
$process.ExitCode
$process = Start-Process "C:\Users\username\Documents\Ranorex\RanorexStudio Projects\yyy\bin\Debug\yyy.exe" -NoNewWindow -Wait -PassThru
$process.HasExited
$process.ExitCode

I found the part with the exit codes here: PowerShell: How to get exit code of a process

Depending on the exit code you could then implement an "if" sentence that would copy the last report to some other folder if the exit code was anything other but "0". You would then have already all the failed reports in a special folder.

Everything that you mentioned is possible to do with PowerShell. I hope that my post gives you some feeling about where to start.

Regards,
McTurtle

barkha
Posts: 18
Joined: Tue May 16, 2017 9:41 pm
Location: Ames, IA
Contact:

Re: Run multiple projects through powershell

Post by barkha » Wed Jan 31, 2018 4:11 pm

Thanks McTurtle,
I was able to work on your scripts and so far I can execute all test and identify failed test to save and zip and send them to my email. However, I am trying to pass a global variable to all tests. How do I do it through powershell? If I type C:\Users\username\Documents\Ranorex\RanorexStudio Projects\xxx\bin\Debug\xxx.exe/param:Global_DeviceName=iPhone6, I get file not found error.
I can't find any information on this.
Thank you

McTurtle
Posts: 297
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Run multiple projects through powershell

Post by McTurtle » Mon Feb 05, 2018 1:47 pm

Hello barkha,

You need to first create a collection of arguments and then pass it with the "-ArgumentList". It would look like this (added parts in bold):

$RxArguments = '/param:Global_DeviceName=iPhone6'
$process = Start-Process "C:\PathToExe\xxx.exe" -NoNewWindow -Wait -PassThru -ArgumentList $RxArguments

Don't try to attach it to the path of the executable.
I found this info on Stackoverflow: ArgumentList parameter syntax

Regards,
McTurtle

barkha
Posts: 18
Joined: Tue May 16, 2017 9:41 pm
Location: Ames, IA
Contact:

Re: Run multiple projects through powershell

Post by barkha » Thu Feb 08, 2018 12:05 am

Hello,
$RxArguments = '/param:Global_Parameter=($parameter)'
$process = Start-Process "Path\bin\Debug\Project.exe" -NoNewWindow -Wait -PassThru -ArgumentList $RxArguments

That is how I am trying to use the code I am tying to pass it to a global variable which is binded to a local variable. I intend to use this variable to update the location for Ranorex reports like this:
I am calling the code function in test case the function has code :
TestReport.Setup(ReportLevel.Debug,local_variable, true);


Nothing is working. I am using version 8 and I know that there is issue with params with space but the path I am passing has no spaces. I also tried passing a global variable and print in textbox but the value is never passed. I tried debugging too but I can't locate the error. Am I missing some connection here?

McTurtle
Posts: 297
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Run multiple projects through powershell

Post by McTurtle » Thu Feb 08, 2018 12:45 pm

Hello barkha,

$RxArguments = '/param:Global_Parameter=($parameter)' can't work.
You need to build the string by using '+': $RxArguments = '/param:Global_DeviceName=('+$parameter+')'

Unfortunately, I don't understand the rest of your post :) Are we still talking about PowerShell or is it something else? Please do explain the question in more detail.

Regards,
McTurtle

barkha
Posts: 18
Joined: Tue May 16, 2017 9:41 pm
Location: Ames, IA
Contact:

Re: Run multiple projects through powershell

Post by barkha » Fri Feb 09, 2018 4:13 pm

Hello McTurtle,
Yes we are still talking about powershell
I want to pass a path through powershell where I want my ranorex reports to be saved.
This path change and I do not want to change it using Ranorex UI.
I saw on a diffrent forum that you can use something like : TestReport.Setup(ReportLevel.Debug,path, true);
And I was trying to use it in ranorex user code method.
So then I have a user method that has this code and take path as an agument, the path parameter is binded to a global variable that is being passed from powershell.
Flow of data:
Powershell> Ranorex>User code (To change the location where the test reports of that project are to be saved)

I hope this clear things up.

McTurtle
Posts: 297
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Run multiple projects through powershell

Post by McTurtle » Mon Feb 12, 2018 5:16 pm

Hello barkha,

You could use the already provided attribute "/rf:". You can pass the report file name and the folder via this parameter. I would try to avoid setting up the report via code.

You can find the rest of the available arguments under the following link: Running Tests without Ranorex Studio

Does this help?

Regards,
McTurtle

barkha
Posts: 18
Joined: Tue May 16, 2017 9:41 pm
Location: Ames, IA
Contact:

Re: Run multiple projects through powershell

Post by barkha » Mon Feb 12, 2018 7:38 pm

Hello Everyone,
Sorry for digressing.
Here is how it works, for people who might want to save their files on new locations:
You need to add /rf:"location" at the end of Ranorex.exe like :

Start-Process -FilePath $exe_path/rf:"location\filename.extension"

hubjohn
Posts: 4
Joined: Mon Feb 12, 2018 10:47 am
Location: Singapore
Contact:

Re: Run multiple projects through powershell

Post by hubjohn » Tue Feb 13, 2018 2:27 pm

I would now like to run all projects sequentially using powershell whenever there is a new version. However, I am new to powershell and do not have a lot of experience.

asdf
Posts: 174
Joined: Mon Mar 21, 2016 3:16 pm

Re: Run multiple projects through powershell

Post by asdf » Thu Feb 15, 2018 4:51 pm

Hi hubjohn,

I don't think that this approach is possible with using the powershell. However, I would suggest having a look at CI tools like Jenkins or Bamboo. I think that this is exactly what you are looking for.

Hope that helps.

barkha
Posts: 18
Joined: Tue May 16, 2017 9:41 pm
Location: Ames, IA
Contact:

Re: Run multiple projects through powershell

Post by barkha » Fri Jul 27, 2018 3:55 pm

Dear hubjon and asfd,
If you are using Mirosoft tfs , you can create a job that run your script that will run after every update. This script can then in turn run your tests.