Page 1 of 1

Switch data source using build parameter

Posted: Thu Jan 25, 2018 11:56 am
by tejas.deshpande
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?

Re: Switch data source using build parameter

Posted: Thu Jan 25, 2018 12:36 pm
by odklizec
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?

Re: Switch data source using build parameter

Posted: Thu Jan 25, 2018 4:19 pm
by krstcs
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.

Re: Switch data source using build parameter

Posted: Mon Feb 11, 2019 9:14 am
by Tolga
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