I want my test to dynamically bind to a different data set at run-time. The data I want the test to use will depend on certain conditions of my application, but the test steps will always be the same.
First, be aware that dynamically binding data is not currently a built-in feature in Test Studio. You can only bind a test to a single data source. However, there is a trick you can implement in code to achieve the same result. The trick relies on swapping the data file to which a test is bound at run time.
Start with a master test. This test may be data bound, but it's not required.
Use some criteria and your code to decide which data file you want to use during that test run.
Swap the physical file on disk with the real file you want to use in your data bound test.
Have your master test call a sub-test that is bound to this data file.
Create a sub-test and bind it to an Excel spreadsheet named Book1.xlsx.
In a coded step in your main test, swap Book1.xlsx for the file you actually want to be used by your sub-test.
Keep in mind that when Test Studio binds a test to an Excel file, it actually makes a copy of the file in the Project\Data folder. Ensure you swap the file located in the Project\Data folder, and not the file in its original location.
You can Create Your Own Test Extension DLL and implement the OnInitializeDataSource in which you can do pretty much anything in code. Place the DLL into the following directory:
- C:\Program Files (x86)\Telerik\Test Studio\Bin\Plugins\
Please note that as of version 2017 R3 the default installation path for new installation is C:\Program Files (x86)\Progress\Test Studio.
It will be called for every test you execute. Whatever OnInitializeDataSource creates and returns will be used as the data source, overriding any file to which the test may have been previously bound.