Using text file as data source for test case

Ranorex Studio, Spy, Recorder, and Driver.
Posts: 4
Joined: Tue Oct 13, 2015 11:05 am

Using text file as data source for test case

Post by ArtoN » Tue Oct 13, 2015 12:24 pm

I just started to learn how Ranorex works and I now stumbled to something I don't know how to solve it right way.

So the situation is this: I have editor window (windows application) which I want to test and I would like to easily fill that editor with some test data. And in the end I would like to save the editor content and verify that the saved file contains what it supposed to contain. (Btw...I would also like to verify editor content directly but it's not possible because Ranorex can't see the content of that editor field...but let's forget that problem for a moment)

So far I have ruled out to have all test data hardcoded to recorded test step. It works but it's not very maintenance friendly. Then I tried to use excel file as data source but I wouldn't be able to use that excel file directly to validate saved file later on so I would like to forget that solution too. Then I tried to do it with code module. It felt like correct solution as I can easily read test file content and add it to variable and then use that variable to fill the editor. And I could use same file to validate saved editor file. But now I'm wondering how to solve file path issue. I have specific test data folder under my solution and that is the place where my text file is. But currently I have hardcoded path to that file in my user code and that doesn't sound good because if someone else tries to run same tests with their environment, the path would probably point to wrong place. So how would you gurus solve this issue? Using some totally different idea or is there some clever way to get path directly to Ranorex test solution root (I already have code which gives path to subfolders under that root folder but I rather have solution where I wouldn't have to cut parts of the path away because I'm not 100% sure that the end of the path will be always the same)?

UPDATE: I went with solution where I read the path in code module and remove extra folders from path if needed. I think that solution should work best because tests are run in desktop and CI environments.

Certified Professional
Certified Professional
Posts: 31
Joined: Wed Mar 25, 2015 4:44 pm
Location: Switzerland

Re: Using text file as data source for test case

Post by Speedboat » Wed Oct 14, 2015 3:04 pm


Here my suggestions:

Have a directory with all files you need for use within your modules in one directory.
The direcory can be on the same level than the main application direcory.

Add .cmd file for the post build prosess which copies this test data path under \\bin\\debug (or bin\release)
(youse only relativ path for this)

Whithin your code module get the filepath by code:
// Composite directory path to bin\\testdata
string sFullFilePath = System.Environment.CurrentDirectory; // gets the directory where your Test.exe runs
sFullFilePath = sFullFilePath + "\\" + %NameOfTestDataPath%; // adds the test data path to the string

// Get a file from the test data path by
sFullFilePath = sFullFilePath + "\\" + %NameOfFile%

It works fine wether you run tests within Ranrex Studio or directly running the Test.exe. And when you deploy the whole release path with subdirectories to another PC, it works as well.

Hope this helps,

Posts: 4
Joined: Tue Oct 13, 2015 11:05 am

Re: Using text file as data source for test case

Post by ArtoN » Wed Oct 14, 2015 4:12 pm

My current solution is quite close to that:
1. Get path to folder where exe is (I was using System.AppDomain.CurrentDomain.BaseDirectory)
2. Check if test data folder can be found from that path. This would indicate that tests are run by CI.
2.1. If test data can't be found, go up in directory tree. This happens when running test from Ranorex Studio. (I'm using System.IO.Path.GetDirectoryName(path) to get parent directory path)
2.1.1. If test data folder is still missing -> Throw an exeption
3. Store correct path to global parameter

I did it like this because I didn't want to have test data files in two different folders in development environment. On CI side I'm anyway doing the copy so that doesn't matter.