In this post we’ll explore the possibility of recording a screencast of TestComplete test runs, the other test tool I use extensively at work.
TestComplete does not have features to record screencast of test execution. However we can use Microsoft Expression Encoder 4 SDK to record videos programmatically from test scripts.
A recoded screencast of test run can help you in investigation of unattended execution or even demo the software or create training videos.
Microsoft Expression Encoder 4 has basic recording features with limited codec support. You can download it free from http://www.microsoft.com/expression/products/encoder4_overview.aspx
While the commercial version Microsoft Expression Encoder 4 Pro provides number of additional features and codecs.
I will use the CLR Bridge & dotNET object available in TestComplete to call the Encoder SDK functions to create the screencast.
Using CLR Bridge in TestComplete we can use .NET assemblies in test scripts and extend the test script code to use features from standard .NET classes as well as custom libraries.
Setting up Encoder SDK in CLR Bridge
Let’s add the Encoder SDK library to the CLR Bridge in TestComplete Project Settings by following steps:
1. Go to TestComplete Project Setting by selecting Current Project Settings from Tools Menu
2. Select CLR Bridge option on left side of Project Properties Pane
3. Click Browse Files button to select the Encoder SDK DLL file. This will display Select Assembly dialog box
4. On Select Assembly dialog navigate to C:\Program Files\Microsoft Expression\Encoder 4\SDK folder and select the Microsoft.Expression.Encoder.dll file
This will add Encoder library to the TestComplete Project and provide access to the internal classes and functions using the dotNET object.
Using ScreenCaptureJob Class in TestComplete Script
Let’s create a instance of ScreenCaptureJob class from the Encoder SDK and call methods to start & stop video recording:
Sub NotePadEditCutTest() Dim wndNotepad, objScreenCaptureJob 'Create a new ScreenCapture Job using it's Constructor Set objScreenCaptureJob = dotNET.Microsoft_Expression_Encoder_ScreenCapture.ScreenCaptureJob.zctor 'Specify the path & name of the Output File objScreenCaptureJob.OutputScreenCaptureFileName = "C:\Data\NotePadEditCutTest.wmv" 'Start the Video Recording using ScreenCaptureJob's Start Method Call objScreenCaptureJob.Start() 'Test Code Call TestedApps.notepad.Run(1, True) Set wndNotepad = Aliases.notepad.wndNotepad Call wndNotepad.Edit.Keys("SOme Text") Call wndNotepad.MainMenu.Click("Edit|Select All") Call wndNotepad.MainMenu.Click("Edit|Cut") Call aqObject.CheckProperty(Aliases.notepad.wndNotepad.Edit, "wText", cmpEqual, "") 'Stop the Video Recording using ScreenCaptureJob's Stop Method Call objScreenCaptureJob.Stop() End Sub
The output screencast will be created in wmv format. This screencast can be edited in Expression Encoder UI.