Page 1 of 1

Change data source in code

Posted: Thu Dec 03, 2015 3:42 pm
by bennylew
Hi,

we have twi kinds of test Environments:

1. with productive data (datafile1.xlsx, Default)
2. with synthetic data (datafile2.xlsx)

I want to use zwo different exel files as data sources. The structure will be identically, the only dfference is the data.

Is it possible to change in code the data source connector from datafile1.xlsx to datafile2.xlsx? Of course I could use two different connectors, but in this case I will lose the data binding from the first connector...

Best regards
benjamin

Re: Change data source in code

Posted: Thu Dec 10, 2015 11:46 am
by bennylew
No idea? :(

Re: Change data source in code

Posted: Thu Dec 10, 2015 4:55 pm
by Support Team
Hi bennylew,

Sorry for the late response.

Unfortunately you need to create two DataConnectors to switch the data, but instead of using the Test Case Properties you could use the following lines of code
var tc = (TestCase) TestSuite.Current.GetTestCase("TestCase");
var source = DataSources.Get("Data2");
tc.DataContext.Source=source;
tc.DataContext.Source.Load();
*Whereby "TestCase" = the name of your Testcase and "Data2" = name of the new Data Connector

Hope that helps.

Regards,
Markus (S)