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?
Switch data source using build parameter
-
- Posts: 32
- Joined: Fri May 20, 2016 9:43 am
Re: Switch data source using build parameter
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:Where the moduleVariable is a variable binded to Global/TestCase/SmartFolder parameter, which you can change from command line. Hope this helps?
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();
}
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
Re: Switch data source using build parameter
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...
Re: Switch data source using build parameter
odklizec wrote: ↑Thu Jan 25, 2018 12:36 pmHi,
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:Where the moduleVariable is a variable binded to Global/TestCase/SmartFolder parameter, which you can change from command line. Hope this helps?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(); }
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)
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)
Can you help me?
Ranorex Version: 8.3.0