How to: Relativize paths of files that a test needs to use

Ask general questions here.
Posts: 8
Joined: Fri Jul 03, 2015 8:13 pm

How to: Relativize paths of files that a test needs to use

Post by justletmesignup » Thu Jul 07, 2016 11:55 pm

Hello all,

I'm back with another question! :) I understand that I'm using the key-phrase "relative paths" in my subject line but I'm fairly certain my question is slightly different from what I can find (w.r.t. past posts on this forum on the topic). Do correct me and possibly point me in the right direction if I'm mistaken though!


I'm using Ranorex to test a software that does analysis of things. In short, these 'things' are misc. files. As such, the software I am testing has a file chooser which lets me dive into the local machine's directories. When I set up my tests, I followed the strategy below (note that I'm not actually using any user code, but using the basic record-click features provided by Ranorex):

1. Open the file chooser
2. Navigate through the machine the test is created via's directory
3. Locate the file and double click to open the file

Already, we can see how the strategy I employed could get messy because if the tree/structure of the machine's directory changes... well, I'll have to re-do that portion of the test.

To clarify what I mean above, I'll write a quick example:

I have a file I want to load as part of this test within the software I'm writing this Ranorex test for. That particular file is located under, 'C:\Folder A\file_to_load.txt'. As such, I'd record my test to start the software and then open the file chooser provided by this software, click into the 'C: drive' and then click into 'Folder A' and then double click 'file_to_load.txt' to open that file. The test would then work if everything stays intact. If for some reason I now need to move 'file_to_load.txt' into a 'Folder B' I'm stuck with the situation where I have to make a new test where I do the above steps except I click into 'Folder B' instead of 'Folder A'.


This is proving troublesome since I'm planning to have these tests also run on 3 other machines. The directory tree/structure of these other machines all vary. That is, 'file_to_load.txt' may exist on 'D: drive' for machine #2, so the test won't work at all.


Is there a way I can have Ranorex recognize immediately where this 'file_to_load.txt' would be? Without having to specifically record my mouse actions of going into a specific hard drive and then into a specific order of folders afterwards?

I hope to have explained this well enough. Let me know if you need additional clarification. Any help/suggestions is appreciated!


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

Re: How to: Relativize paths of files that a test needs to use

Post by odklizec » Fri Jul 08, 2016 7:24 am


In my opinion, the easiest and least complicated way to load a file (via Windows FileOpen dialog) is to enter a whole path to "File Name" input...
SelectFile.png (29.4 KiB) Viewed 1620 times
This eliminates a complicated and possibly highly unreliable steps to select the file via tree. If you don't want to mess with code, you should store the path to files in data connector, connected to variable, which should be used in SetValue or KeySequence command.

As for testing on multiple systems, you should always make sure the testing environment is configured the same way on all systems! This is a crucial part of reliable test automation. At least if you want to use one test automation solution with exactly the same input data.

If you cannot guarantee the required files are always at the same place, then I'm afraid, you will either have to find the proper location of files via code (before entering the path to input). Or you need to create a different data connector file for each system you want to run your test at. Eventually, you can pass the path via command line (while starting test on individual systems) to a global parameter of your choice and then merge the path from global parameter with with file name stored in data connector (just before entering the path to file name input).

But in my opinion, by far the easiest solution is to make sure the testing environment is the same across all computers/VMs ;)
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

Posts: 8
Joined: Fri Jul 03, 2015 8:13 pm

Re: How to: Relativize paths of files that a test needs to use

Post by justletmesignup » Fri Jul 08, 2016 5:56 pm


Thanks for the response!

I had a feeling that the method I used isn't the most optimum by far. I'll go and make adjustments to my tests by typing out the full path in the file chooser. Perhaps I can do some additional exploration and see if it's possible to do something fancy with this suggestion.

Hmm, after thinking about it I also agree with what you say when I should ensure all the testing environments are consistent. I'll look to advocate that as well!