Category Archives

Test Automation

Implementing the Braidy Tester’s automation stack

Twelve moths ago, before my last project started I went on a journey. The intended destination was test automation nirvana. The way to get there, or so I thought was to combine WatiN with The Braidy Tester’s Automation Stack. The end result, I hoped would be the Deep Thought of test automation. It didn’t quite work out that way, and I would like to share some o the challenges we faced.

The Braidy Tester’s automation stack

I am not going to describe the architecture in detail of the Braidy Tester’s automation stack, as Michael Hunter has already covered that in great detail. What IS important however is the pieces that we chose. The key aspects of the stack that we decided implement were:

  • Logical Functional Model The logical functional model is a user centric view of how the application is used. For example: Logical.Google.Search("Bruce McLeod");
  • Physical Object Model The physical object model is an abstraction layer that hides the implementation and automation semantics details from the tests. For Example:Physical.Google.btnSearch.Invoke();
  • Execution Behaviour Manager Execution behaviours are a way of loosely coupling execution actions. They allow executions to be composed, as well as executed in different sequences.
  • Loosely Coupled Verification Instead of littering your tests with assert statements, loosely coupled verification takes a snapshot of the application, calculates an expected state based on your execution behaviour and then compares it to the actual state after the action is performed.
  • Test Data Providers Test Data providers remove the need for test data to be hard coded into the test by moving it out, into a database in our case.

Things that worked brilliantly in the automation stack

The separation into the logical and physical layers worked exceptionally well. The test cases become very clean and concise. We added another lower level layer called the controller in place of the Application Internals model.

The controller essentially was an abstraction later over WatiN and our control definitions. This makes the entire stack easily portable from one automation technology to another, so the transition will be very easy when the new automation tools ship in the next version of Visual Studio Team Test, if we decide to change.

Implementing Execution Behaviours with Delegates

The idea behind Execution Behaviours is that you use attributes on a method that matches the delegate signature to perform one of the following actions:

  • Execute all the specified actions in the listed sequence. ExecuteInSequence
  • Execute one of the actions "randomly". ChooseAny
  • Execute all the actions in the listed sequence until some condition is met. ExecuteUntil

Execute in sequence is straight forward and is used to compose actions.

[CompositeExecutionBehavior("OpenSearchPage", "WebSearch")]

public static void Search(TestDataProvider dataProvider)

{

   TestActionDelegate myDelegate = TestExecutionManager.ExecuteInSequence(Logical.Google. Search(TestDataProvider dataProvider);

}

With delegates being used and the possibility of execution sequence order changing, it becomes necessary to provide inherit record and replay for actions. We chose to use a version of the command pattern and use .net serialization to achieve this. We also had to package up the parameters into an array of objects to the could be serialized. The implementaiton of one of our actions in the physical layer would look something like this:

public static void OpenSearchPage(TestDataProvider dataProvider)

{

   // Add this action to the command list and serialize it

   object[] parameters = { dataProvider };

   ExecutionManager.Add(parameters);

   // Open the search page

   SearchModel searcher = new SearchModel();

   searcher.OpenSearchPage(dataProvider);

}

This then calls the physical layer that actually does the work. All this loosely coupled goodness is great, except that we only ever used the one type of execution behaviour, execute in sequence. As a result our code could have actually looked like this instead if it was hard coded in the logical model.

public static void Search(TestDataProvider dataProvider)

{

   SearchModel searcher = new SearchModel();

   searcher.OpenSearchPage();

   searcher.Search(dataProvider);

}

That code is much simpler and easier to maintain, and removes the method signature matching constraints that delegates impose. For us it would have been a much better way to go, simply because we would have removed the constraints required by functionality that we didn’t actually implement.

In the next post, I’ll run through some of the benefits and challenges we had implementing loosely coupled verification.

Test Automation Watin0 comments

Another UI Automation testing framework

To complement white there is another UI Automation library on codeplex. The UIA Verify framework has been developed by the UI automation team. This library is used to ensure that your application or control correctly implements the UI automation providers that can then be used by projects like white. To quote the project page on codeplex.

UI Automation Verify (UIA Verify) Test Automation Framework

UIA Verify is a test automation framework that features the User Interface Automation Test Library (UIA Test Library) and Visual UI Automation Verify (Visual UIA Verify), the graphical user interface tool. The framework facilitates manual and automated testing of the Microsoft (R) User Interface (UI) Automation Provider implementation of a control or application. The majority of the UIA Verify functionality is provided through a dynamic link library (e.g., UIATestLibrary.dll) that contains the code for testing specific UI Automation functionality and supports logging of the test results.

With the Visual UIA Verify, you can quickly find and select any UI element anywhere on the desktop. Based on the specific control type and the supported control patterns, UIA Verify provides the built-in test scenarios prioritized for the particular UI element. Developers can add additional test scenarios by adding the code to the UIA Test Library. The tool can output the test results or the summary in various forms. Visual UIA Verify can output test details in HTML



Test Automation0 comments

UIAutomation testing with White

The guys at Thoughtworks have released yet another open source project. This one is called white and is on codeplex http://www.codeplex.com/white/. What is white? White is a library that sits on top of the .Net 3.0 UIAutomation API’s. I have written one of these myself and we use it internally, so I haven’t looked at white.

Combined with WatiN, and ItiN if you use InfoPath, with white you should be able to write 100% of your tests using managed code in Visual Studio 2008. We do!

Test Automation1 comment