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: 7470
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
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...

Tolga
Posts: 4
Joined: Tue Oct 16, 2018 2:52 pm

Re: Switch data source using build parameter

Post by Tolga » Mon Feb 11, 2019 9:14 am

odklizec wrote:
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?

So if I use this method I get an exception: "No row has been selected. "

Code: Select all

bei Ranorex.Core.Data.DataContext.Get(String variableName, DataBindingType type)bei Ranorex.Core.Data.DataContext.Get(IDataBindingInfo dataBindingInfo)
bei Ranorex.Core.Data.DataConnectorBindingInfo.get_Value()
bei Ranorex.Core.Testing.TestModuleLeaf.ReportAndAddBindingToActivityStack(ReflectionDataProvider refDataProvider)
bei Ranorex.Core.Testing.TestModuleLeaf.RunInternal(DataContext parentDataContext, Int32 iteration, Int32 iterationCount, Boolean skipIteration)
My Solution is build like this:

Code: Select all

- TestCase Main (with Main DataSource, not going to change)
    - Setup
        - SetDataSource("LevelRepetition")
    - SmartFolder BuildData
    - SmartFolder LeveRepetition (with possibly different DataSources depending on the Row in Main DataSource)
As you can see above I want to change the DataSource of the SmartFolder "LevelRepetition". In the RanorexReport the chosen DataSource is actually shown. But in the first Method where through DataBinding one value out of that DataSource is needed, I get the exception: "No row has been selected. "

Can you help me?

Ranorex Version: 8.3.0