Telerik blogs

Q3 release for WebUI Test Studio (coming in few weeks) is jam packed with tons of new features. Many of these features are direct result of customer’s feedback. In Q3 we added Chrome support, test run scheduling, visual debugging and logical steps in the test explorer in addition to many more enhancements. For more details on these new features, please refer to the pre-release blog post here and make sure to sign-up for our Q3 release week webinar here.

One of the other features that might not be visible to the eye in Q3 is our enhanced extensibility support for test execution. The execution extensibility model has been requested by several customers to help them integrate WebUI Test Studio better into their own environments that contains custom results reporting repositories and custom code defect  tracking systems. With the new execution extensibility we exposed an object model that gives customers full control and freedom to integrate WebUI Test Studio in any environment regardless of its architecture.

To help demonstrate the execution extensibility model in Q3, I’m going to build a simple “Execution Extension” to WebUI Test Studio that takes the results of a TestList once complete and tweets that result to a twitter account that I created (@ResultTweets). This way, I can get my test results anywhere as soon as they are complete. I can also get them directly from my iPhone or any other device that runs a twitter client.

So let’s get started….

First let’s create a class library project in Visual Studio. I’m going to use a C# project but you can use any other .NET language you  might be comfortable with.

Once the project is created, let’s go ahead and add references to four dlls that should be available in the %ProgramFiles%\Telerik\WebUI Test Studio\Bin\

1. ArtOfTest.Common.dll

2. ArtOfTest.Common.Design.dll

3. ArtOfTest.WebAii.dll

4. ArtOfTest.WebAii.Design.dll

These 4 dlls contain the object model for both our runtime and design time extensibility.

Now, we are ready to code. Let’s add a class file and call it TweetResultsExtension.cs

The class needs to simply import the ArtOfTest.WebAii.Design.Execution namespace which contains the execution extensibility.

 

The namespace above will contain an IExecutionExtension that our class will need to implement:

 

image

 

Right click on the IExecutionExtension in VS and select “Implement Interface”. This will simply stub out all the methods and notifications exposed by WebUI Test Studio for you to consume. The API is pretty extensive and gives you pretty much access to all the difference execution stages in the product. 

Here is a break down of IExecutionExtension:

 

 1: #region [ IExecutionExtension Members ]
 2:  
 3:  /// <summary>
 4:  /// Before a test is about to start.
 5:  /// </summary>
 6:  /// <param name="executionContext">The execution context the test is running under.</param>
 7:  /// <param name="test">The test we are about to start running.</param>
 8:  public void OnBeforeTestStarted(ExecutionContext executionContext, Test test)
 9:         {
 10:         }
 11:  
 12:  /// <summary>
 13:  /// After each test is completed, this method is called. 
 14:  /// </summary>
 15:  /// <param name="executionContext">The execution context the test is running under.</param>
 16:  /// <param name="result">The actual result of the test</param>
 17:  public void OnAfterTestCompleted(ExecutionContext executionContext, TestResult result)
 18:         {
 19:         }
 20:  
 21:  /// <summary>
 22:  /// Before a test list is about to start execution.
 23:  /// </summary>
 24:  /// <param name="list">The testlist that is about to start.</param>
 25:  public void OnBeforeTestListStarted(TestList list)
 26:         {
 27:         }
 28:  
 29:  /// <summary>
 30:  /// After the test list is completed.
 31:  /// </summary>
 32:  /// <param name="result">The entire RunResult object</param>
 33:  public void OnAfterTestListCompleted(RunResult result)
 34:         {
 35:         }
 36:  
 37:  /// <summary>
 38:  /// Called only on a step failure.
 39:  /// </summary>
 40:  /// <param name="executionContext">The execution context a test is running under.</param>
 41:  /// <param name="stepResult">The step result that just failed.</param>
 42:  public void OnStepFailure(ExecutionContext executionContext, AutomationStepResult stepResult)
 43:         {
 44:         }
 45:  
 46:  /// <summary>
 47:  /// Will be called when the test is databound. Use it to return your own data source.
 48:  /// </summary>
 49:  /// <param name="executionContext">The execution context</param>
 50:  /// <returns>The data source else null.</returns>
 51:  public System.Data.DataTable OnInitializeDataSource(ExecutionContext executionContext)
 52:         {
 53:  return null;
 54:         }
 55:  
 56:  #endregion

 

Few notes about the code above:

 

1. ExecutionContext: The context is an object that gives you pretty much all other objects in context of the current execution. For example, from this object you can access the runtime Manager object, the ActiveBrowser, the Log object, the Find object…etc. All the runtime objects we are using to execute your test. If you use our WebAii framework, you should already be familiar with these objects.  

2. Result objects: The RunResult object contains a list of “TestResult” objects for each test that executed. Each TestResult in turn has an AutomationStepResult list that represents the result for each step that executed. You simply have access to all the metadata of the execution so you can generate your own reports if you choose to or persist the results in your own format in the repository of your choosing. 

3. OnInitializeDataSource: If you wish to bind a test to your own custom data source. You can simply return a DataTable from this method. Once you return a DataTable, we will use that Table to data drive the test. If you don’t care about this, you simply need to return null. 

OK. Now that we have the API stubbed out, for the purpose of the Auto-Tweet extension, I simply want to get notification when a test list is done executing. So I’m simply going to use one method: OnAfterTestListCompleted(RunResult result).  

Given that twitter allows status updates to be only 140 characters, I’m going to craft a custom simple string that represents that result, then I’m going to call PostTweet() which will post that result string to my twitter account using twitter API: 

/// <summary> /// After the test list is completed. /// </summary> /// <param name="result">The entire RunResult object</param> public void OnAfterTestListCompleted(RunResult result)
{
  string msg = string.Format("TestList '{0}' completed on '{1}'. ({2}/{3}) Passed", result.Name,result.EndTime, result.PassedCount, result.TestResults.Count);
  PostTweet(msg);
}

 

Now, let’s compile this class library and deploy this extension. Extension deployment is pretty simple. Copy the dll and drop it in the “Plugins” folder under bin:

 

%ProgramFiles%\Telerik\WebUI Test Studio\Bin\Plugins

 

DONE! 

Now each time any of my testlists execute, I will get a status update on that twitter account…. I and all my colleagues interested in test results can simply follow that account and get real-time updates of execution results  Smile.

 

image

 

In summary, the new execution extensibility opens up the door and enables an endless number of possibilities in how you can customize and extend test results and persist them. It also gives our Automated Testing Tools the flexibility to integrate easily into any customer system.

 

Stay tuned for more on Q3 features…

 

Thanks,

Faris (@farissweis)


Comments

Comments are disabled in preview mode.