Switch data source using build parameter

Ask general questions here.
tejas.deshpande
Posts: 32
Joined: Fri May 20, 2016 9:43 am

Switch data source using build parameter

Post by tejas.deshpande » Thu Jan 25, 2018 11:56 am

I would like to switch between two .csv files as data source where selection would depend on a build parameter.
Eg. ranorex.exe /pa: C:\DataSource2.csv

Any suggestions?

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

Re: Switch data source using build parameter

Post by odklizec » Thu Jan 25, 2018 12:36 pm

Hi,

I believe it's not possible to load a data source file via code? But what you can do is to (manually) create two data connectors, then use below code to load the one you want:

Code: Select all

    
if (moduleVariable = "DataSource2")
{ 
var tc = (TestCase) TestSuite.Current.GetTestContainer("TestCaseName");  
    var source = DataSources.Get("DataConnector2");  
    tc.DataContext.Source=source;  
    tc.DataContext.Source.Load();  
}
Where the moduleVariable is a variable binded to Global/TestCase/SmartFolder parameter, which you can change from command line. 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

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

Re: Switch data source using build parameter

Post by krstcs » Thu Jan 25, 2018 4:19 pm

If you really need a dynamic data source (which is what you are asking) then you need to use a database. SQL Server Express is free and you can create a local DB file that stays with your Ranorex solution. Then you can use a well constructed SQL query to get the data you want each run.
Shortcuts usually aren't...