How can I set an other working directory after build

Ask general questions here.
JToelstede
Posts: 55
Joined: Fri May 24, 2013 12:57 pm

How can I set an other working directory after build

Post by JToelstede » Fri Nov 22, 2013 1:52 pm

Hi together,

we are testing an Java-appliction(AUT) and in the root-Directory of this application are config-files which are loaded at the start of the AUT. So I set the working-directory of my Testsuite in RanorexStudio to the root-directory of AUT and it work fine.
But we have different environments were the testautomation/testsuite should run (integration-test, acceptance-test and production) and for each environment we have an separate AUT and thus for each a different working-directory.
On every switch of our environment I have to reconfigure the working-directory in RanorexStudio an to rebuild the project.

Is it possible to set the working-directory dynamically with an excel- or csv-file.
I actually use an csv-file which contains the full path of AUT and I start the AUT rigth at the beginning of the testrun.

Thanks for help.

Kind regards,
Joerg

Swisside
Posts: 92
Joined: Thu Oct 10, 2013 10:40 am

Re: How can I set an other working directory after build

Post by Swisside » Fri Nov 22, 2013 2:14 pm

One way to fix this is to use a global parameter to store the path of your AUT.


Then you can start your test with a command line like this

mytest.exe /param:AUTPath=path

That is the simpliest way.
A simple thank you always does wonders !

JToelstede
Posts: 55
Joined: Fri May 24, 2013 12:57 pm

Re: How can I set an other working directory after build

Post by JToelstede » Mon Nov 25, 2013 9:45 am

Hi Swisside,

thanks for your post. I will try it out.

But isn't there a possibility to set the working directory with my csv-file?
The path already exists in the csv-file and it would be fine to manage it with this data-file.

Regards,
Joerg

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How can I set an other working directory after build

Post by Support Team » Tue Nov 26, 2013 1:05 pm

Hi,

If I got this correctly you just need to bind the path to the AUT, which is saved in the csv file, to a module variable which can then be used to start your application under test as described here: Data Driven Testing.

Regards,
Markus
.
Image

JToelstede
Posts: 55
Joined: Fri May 24, 2013 12:57 pm

Re: How can I set an other working directory after build

Post by JToelstede » Tue Nov 26, 2013 3:40 pm

Hi Markus,

I allready use the path to start the application in this way you described.
But in the properties of the Testsuite you can set an working Directory on the debug tab.
Working directory.jpg
For integration test environment
Working directory.jpg (17.65 KiB) Viewed 1431 times
Working directory_acceptance.jpg
For acceptance test environment
Working directory_acceptance.jpg (6.26 KiB) Viewed 1431 times
This directory is different for every testenvironment and I have to change the path for the working directory everytime I switch to an other environment.
I would like to know if there is a possiblity to set this path automaticaly by using the given path out of my testdata sheet.

Thanks for help.

Regards,
Joerg

Swisside
Posts: 92
Joined: Thu Oct 10, 2013 10:40 am

Re: How can I set an other working directory after build

Post by Swisside » Tue Nov 26, 2013 4:27 pm

Hello

You will find an example on how to set your working directory.

How it works :

1) The Excel file "MyTestData.xlsx" contains a column with the the working directory you want

2) You bind the column to a variable in SetDirectory.rxrec

3) You change the Working directory in SetDirectory.UserCode.cs (TestSuite.WorkingDirectory is used to set or get the value of the working directory)

Once you adapted and added the example to your actual test case, all you have to do is change your working directory in the xlsx file (as you wanted) !


Hope it helps


Regards
Attachments
DynamicallySettingWorkingDirectory.zip
Example
(98.44 KiB) Downloaded 136 times
A simple thank you always does wonders !

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How can I set an other working directory after build

Post by krstcs » Tue Nov 26, 2013 4:53 pm

So, I think a question needs to be asked at this point that will help shed some light on the real issue.

Joerg, are you wanting to set the working directory for your system under test (this is what Swiss is talking about), or are you wanting to set the working directory for you Ranorex TEST?

I think there is some confusion about what your are trying to accomplish, so if you can answer that question maybe it will clear things up for us to help you. :D
Shortcuts usually aren't...

JToelstede
Posts: 55
Joined: Fri May 24, 2013 12:57 pm

Re: How can I set an other working directory after build

Post by JToelstede » Thu Nov 28, 2013 8:41 am

First of all many thanks to swisside for the example project. :!:
Ok, I will try to explain it once again.

We are testing a JavaClient app with server interactions. Some of the data the client receives from the server is saved in a temp directory of the application (starts with an underline). The directory is also used for changes which will be saved first in the local temp-folder and after a user commit they will be send to the server. If no connection to the server is available because of no internet connection he could work on his local temp-folders and the data will be sent to the server as soon a connection is available.

We have three test environments (developer test, integration test, acceptance test) and the production environment and for each environment exists a separate JavaClient with their own working directory.
working_directory.jpg
working_directory.jpg (22.53 KiB) Viewed 1407 times
When the JavaClient is started for the first time it checks the availability of the temp folders (those that start with an underline) and if they not exist, the client will create them.
During the automated tests with ranorex the working directory of the JavaClient is in the debug folder of the RanorexTestsuite and not in the folder of the JavaClient.
Because of this it is possible that I will get data inconsistency and so my testresult will not be meaningful.

Now I want to set the working directory for my AUT (JavaClient) during the testrun with Ranorex to the correct folder.
working_directory_2.jpg
working_directory_2.jpg (26.43 KiB) Viewed 1407 times
In my testdata.csv I still have the rigth path for the "run application"-command of Ranorex so that I can start a testrun for each testenvironment by selecting the AUT in my databindings. The problem is that I didn't know how to set the working directory dynamicaly.

I tried the solution of swisside suggested, but it seems that it doesn't work. In my UserCode I set the working directory as in the example from swisside before I call the "run application"-command and after which I set an additional Report.Info statement for the working directory.
Before the next testrun I deleted the temp-folders of my AUT in both directories ( in the correct working-directory of my JavaClient and in the Debug-Folder of Ranorex) so that the JavaClient would create it new.
I start the testrun and the UserCode told me that the working directory is set to the right folder (JavaClient) before and after the "run application"-command. Than I checked where the temp-folders have been generated and I found them in the Debug-Folder of Ranorex and not in the working-directory of my AUT.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How can I set an other working directory after build

Post by Support Team » Thu Nov 28, 2013 9:15 am

If I get the use case right, then all you need to do is set the "Working Directory" property of the "Run Application" action correctly. Just open the properties for the "Run Application" action and set the working directory or in user code use the working directory argument for the Host.RunApplication method.

If you want the working directory always to be the directory of the EXE file you start (e.g. if you set the EXE file path using variables), then just use the Path.GetDirectoryName method on the EXE file path to get the working directory path.

Regards,
Alex
Ranorex Team
.
Image

JToelstede
Posts: 55
Joined: Fri May 24, 2013 12:57 pm

Re: How can I set an other working directory after build

Post by JToelstede » Thu Nov 28, 2013 10:26 am

Hi Alex,

thanks for your post.
Now I start the AUT with the following code snipped in my User-Code:

Code: Select all

Report.Log(ReportLevel.Info,"Run the application '" + EXCEL_PATH_AUT + "' with working directory '" + System.IO.Path.GetDirectoryName(EXCEL_PATH_AUT) + "'!");
Host.Local.RunApplication(EXCEL_PATH_AUT, "", System.IO.Path.GetDirectoryName(EXCEL_PATH_AUT), false);
The variable EXCEL_PATH_AUT is bounded to my csv-file which contains the whole path of the AUT (for excample "C:\Program Files (x86)\AUT_integration\aut.exe)

It ist working perfect and that was exactly the solution I was searching for.

Thanks a lot and many thanks to swisside too.

Best Regards,

Joerg