Execution Extension
Test Studio has enhanced extensibility support for test execution. This model helps integrate Test Studio better into your environment that contains custom results reporting and code defect tracking.
To demonstrate the execution extensibility model, let's build a simple Execution Extension to Test Studio that writes the results of a test list to a text file.
1. Create a Class Library project in Visual Studio. This example uses C#.
2. Add references to three DLLs from C:\Program Files (x86)\Progress\Test Studio\Bin\
ArtOfTest.WebAii.dll
ArtOfTest.WebAii.Design.dll
Telerik.TestStudio.Interfaces.dll
Also add the following .NET references (these are required for the demonstrated code):
System.Runtime.Serialization
System.Windows.Forms
3. Add the following using statements to the class file:
4. The ArtOfTest.WebAii.Design.Execution namespace contains an IExecutionExtension that the class library needs to inherit and implement:
5. Right click on IExecutionExtension and select Implement Interface > Implement Interface. This displays all the methods and notifications exposed by Test Studio. Here are definitions for each IExecutionExtension member:
The OnInitializeDataSource() function cannot be left empty and should return null if not being used. Test Studio takes into consideration only the first non null data table (if you are using more than one plugin, the first one to return non null data table is used).
The rest of the functions, which you're not using, should be left empty (remove throw new NotImplementedException).
A few notes about the code above:
ExecutionContext - The context is an object that gives you mostly all other objects in context of the current execution. For example, from this object you can access the run-time Manager object, the ActiveBrowser, the Log object, the Find object, etc. These are the run-time objects are used to execute your test. If you use the Telerik Testing Framework or coded steps, you are familiar with these objects. It also exposes the ExecutionContext.ExecutingTestAsStep property, which distinguishes between tests being run normally or as a subtest.
Result objects - RunResult contains a list of “TestResult” objects for each test that is executed. Each TestResult has an AutomationStepResult list that represents the result for each step that executed. You have access to all the metadata of the execution so you can generate your own reports.
OnInitializeDataSource - Bind a test to a custom data source by returning a DataTable from this method. Use that DataTable to data drive the test. As of internal build 2012.1.816, if this method returns a DataTable, it will be used regardless if the test is data bound or not. For older versions, it will only get called if the test is bound to a data source or if the InheritParentDataSource Test Property is checked.
Scope of Variables - Notice that OnBeforeTestListStarted() and OnAfterTestListCompleted() are called by the Scheduling Server, while OnBeforeTestExecution and OnAfterTestExecution are called by ArtOfTest.Runner on the Execution Server. This means that if you initialize variables inside of OnBeforeTestListStarted or OnAfterTestListCompleted, you will not reliably have access to these variables inside OnBeforeTestExecution or OnAfterTestExecution, and vice versa. To use the same variables in both sets of methods, you can lazy initialize the variables to ensure that they are not null.
6. For the first example, we'll add code to the OnAfterTestListCompleted method to write the result of a test list as a basic string to a text file:
7. Compile the class library.
8. Deploy the extension by copying the DLL from the %Project Folder%\ClassLibrary1\ClassLibrary1\bin\Debug to the following directory:
- C:\Program Files (x86)\Progress\Test Studio\Bin\Plugins\
9. Now execute a test list. The result string is written to the defined text file.
Example of OnInitializeDataSource Method
Let's see another example using the OnInitializeDataSource method. This assumes that your test is already binded to an Excel file, and each Excel file has matching column names.
1. Add the following code to that method:
2. Now add the following ImportExcelXLS method within the same public class:
3. Rebuild the class library, copy the resulting DLL file, and paste it into the Plugins folder (overwriting the existing file).
4. When you execute a data driven test, you are prompted to select an Excel file (.xls or .xlsx). You have two choices:
Select a new Excel file and press OK.
Press Cancel to use the original data source.
Remote Execution Behavior
It was mentioned above in terms of the scope for variables, that some methods are executed only on the machine, where the scheduling server for the current remote setup is located. It is important to know how will the execution extension behave in case of different execution scenarios. For all of the listed configurations the built custom dll file needs to be copied in the C:\Program Files (x86)\Progress\Test Studio\Bin\Plugins\ folder on each remote machine.
Scheduling Server Setup
This feature allows only one machine to have a running scheduling server and multiple machines to be connected to it and serve as execution clients. In this case the complete set of execution extension methods will be executed on the scheduling server machine only.
All execution machines will not execute OnBeforeTestListStarted() and OnAfterTestListCompleted() and will only recognize the OnBeforeTestStarted() and OnAfterTestCompleted().
CI Setup
In the context of Continuous Integration setup - running test lists using the ArtOfTest.Runner.exe with the list option, will execute all methods in the extension.
However, if using the test option to run a single test, the agent will not execute OnBeforeTestListStarted() and OnAfterTestListCompleted() and will only recognize the OnBeforeTestStarted() and OnAfterTestCompleted().