Using Global variable as Path for Data Source

Class library usage, coding and language questions.
mcarolo
Posts: 1
Joined: Fri Nov 02, 2018 3:07 pm

Using Global variable as Path for Data Source

Post by mcarolo » Fri Nov 02, 2018 3:18 pm

Hello.

It's my first post here, and I wanted to start with a generic "Hello", seems nice and good.
I'm a developer from Italy, recently approaching Ranorex. So, not a lot of knowledge about testing, but a lot about programming.

I'm taking a leftover suite implemented by a tester with Ranorex, and trying, in order to better understand the product and get my own package of knowledge to "rewrite" the existing test suite, implementing my own version of the existing test suite and trying to optimize it at my best using the top of the developer skills I have.

This all to ask you a simple question, as written inside the title.

Is it possible to set a Data Source from a path defined as a global variable inside the solution?

I want to make the testing solution as flexible as possible, and that will help a lot. I've a lot of data sources inside an external folder...

Thanks for any reply, and greeting from Italy!

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

Re: Using Global variable as Path for Data Source

Post by odklizec » Mon Nov 05, 2018 9:15 am

Hi mcarolo and welcome here. As far as I know, there is no way to use a global parameter as a variable in data connector settings dialog. The only way would, most probably, be using dynamic loading of data connectors via code? But I think this would require a lot of unnecessary work and potential source of issues? Anyway, you can use relative paths in data connector settings. So if you are concerned about absolute paths, simply replace them with relative counterparts.
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

MichalSk
Posts: 37
Joined: Fri Jul 10, 2020 9:23 am
Location: Pforzheim, Germany

Re: Using Global variable as Path for Data Source

Post by MichalSk » Tue Sep 15, 2020 9:44 am

Hello odklizec,

I have a similiar problem right now, and fortunately found this topic.

In my case, I am executing my tests on a different machine, where I develop it. Therefore as soon as I run my tests, on the Test Suite Runner on a different machine, the data sources cannot be found.

Can you tell me how can I make the path more flexible??

For example if my path is: C:\Users\....\ChangeMinAndMaxValue_DataSource.csv and I want to only look inside my project files without: C:\Users\...

Thanks in Advance!
Last edited by MichalSk on Wed Sep 16, 2020 8:00 am, edited 1 time in total.

User avatar
Stub
Posts: 515
Joined: Fri Jul 15, 2016 1:35 pm

Re: Using Global variable as Path for Data Source

Post by Stub » Tue Sep 15, 2020 3:43 pm

I quite often form paths based off the location of the executing test assembly. I have our test solution configured to build to a particular bin folder, so when I need to build the path to some test data files I can easily navigate the folder structure to get what I'm after.

That approach works well for me when building the Rx test solution using MSBuild. It didn't work so well when I started experimenting with the Ranorex Agent recently, but IIRC I worked around that be incorporating the test data into the build outputs. Or something along those lines. We don't have sufficient Rx licences that I have been able to experiment too much with that.

No idea about Rx Data Sources though. I've thus far stuck with the Simple Data Tables. One of these days I'll venture into more advanced data connectors.

MichalSk
Posts: 37
Joined: Fri Jul 10, 2020 9:23 am
Location: Pforzheim, Germany

Re: Using Global variable as Path for Data Source

Post by MichalSk » Wed Sep 16, 2020 7:26 am

Hello stub,

alright thanks for sharing your experience/thoughts!

Until now we didn't worked with the Ranorex Agent, therefore i cann't say anything about that. Like I mentioned, when I have a working solution, I turn the configuration to "Release" and then build the project and use the "Release" folder to execute it, on a other computer/machine.

Maybe it's possible to make the path shorter, to only search in the project folder after the data source..

If you find a working solution, I would appreciate if you share it with us, otherwise let's wait for Mr. odklizec to be back :D

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

Re: Using Global variable as Path for Data Source

Post by odklizec » Wed Sep 16, 2020 7:52 am

Hi,

You should definitely not use data sources with fixed path (c:\somehting\...). I would suggest to use relative path instead, e.g. .\Data\DataConnectorFile.csv
Then you should simply include the csv files to project and set the to copy to output directory, as shown for example here:
add-file-as-resource-t13413.html#p52728
This should assure that the csv file is available at expected position, regardless of target machine/folder. Hope this helps?
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

MichalSk
Posts: 37
Joined: Fri Jul 10, 2020 9:23 am
Location: Pforzheim, Germany

Re: Using Global variable as Path for Data Source

Post by MichalSk » Wed Sep 16, 2020 10:12 am

Hey,

Thanks for the reply - I followed your steps, but unfortunately it's still not working... I will show you some screenshots.

My relative path looks right this:
Relative_Path.png
Then I build the project and start the Test suite from the Release folder on a other machine, via the Test suite Runner.
If I click on the Data sources I still get an error telling me: "Could not find file..."

Also I realized that after I build the project with the path shown, he is creating automatically a new file in the project folder..
Files_get_added_automatically.PNG
I guess my relative path is not optimal??
You do not have the required permissions to view the files attached to this post.

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

Re: Using Global variable as Path for Data Source

Post by odklizec » Wed Sep 16, 2020 11:00 am

Hi,

At first, uncheck the option "Copy file to project". This option copies the file to bin root folder. I simply don't like this option because it creates a mess ;) Then follow the steps from my previous post. You need to include the file in project and set "Copy to output directory" to "true". Then if you run the test, build should copy the file (including DataSources folder) to "bin" folder and Ranorex should not have a problem to find and use the file.
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

MichalSk
Posts: 37
Joined: Fri Jul 10, 2020 9:23 am
Location: Pforzheim, Germany

Re: Using Global variable as Path for Data Source

Post by MichalSk » Fri Sep 18, 2020 3:55 pm

Hey,

I followed your suggestions and found out, that I forgot something else to do, which most likely caused problems in finding the files...

Inside my project, I created a new folder "DataSources" and also added it to my TSVN repository - so far so good.
But I didn't realized that when building the "Release" folder, Ranorex will create a "DataSources" folder as well, and that one I need to include in the repository as well :D

Therefore when running the test suite from the Release folder, Ranorex wasn't able to find the Data source files.
I haven't had a chance to test the problem yet, but will give it another try soon. Then I will update you guys.

vishni
Posts: 14
Joined: Wed May 26, 2021 11:51 pm

Re: Using Global variable as Path for Data Source

Post by vishni » Thu Oct 28, 2021 1:54 pm

Hi,

I have similar problem, has there been a solution on this.
I have 2 test environment. The test data is different on both. I have created testdata folder with 2 folders on it. One for dev and QA environment. I have post build script that would copy the file to /bin/debug/testdata based on build configuration say if it's dev, then copies data from testdata/dev bin/debug/testdata/. So my Excel connector path looks like ../my project/bin/debug/file.xls. this works fine on local but on Jenkins the path is not resolved to correct one. Any suggestions?

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

Re: Using Global variable as Path for Data Source

Post by odklizec » Fri Oct 29, 2021 9:27 am

Hi,

Simply use relative path (relative to the tests app) like this: .\Data\DataConnectorFile.xls
This should avoid issues with different base path on different platforms.
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