Sunday, June 26, 2011

Venturous: Web Forms WAT framework

Venturous is a library for testing ASP.NET Web Forms applications through the browser. In many ways it is the same as already existing frameworks like Selenium, Watir, WatiN and WebAii. The reason for writing it is because I have some specific design goals in mind that I believe will be important to the success of our testing efforts. I’ll go through some of them in this post.

As I mentioned, there are already frameworks out there that do basically the same thing. In fact Venturous uses the excellent WatiN framework behind the scenes to do the actual work of interacting with the browser. Venturous is written as a layer on top of it, exposing it’s own API surface.

Venturous is specialized towards ASP.NET Web Forms applications. The Web Forms framework has some peculiarities that can make testing through the browser problematic. It is important that tests fail for the right reasons. They should be written in a way that makes them tolerant to changes that don’t break the functionality that is being tested. The goal of Venturous is to help you with this.

Control Hierarchy

As you probably know, Web Forms is built on the concept of a control hierachy where a page contains controls like panels and grids, and these controls again contain more controls. The IDs of the HTML elements are generated by combining the ID given to the control with the IDs of all the parent controls like the path in a folder structure. So whenever the structure of the page changes, if your tests rely on the ID of an HTML element, it will break.

To overcome this, Venturous allows you to write test-controls that follow the control hierarchy. In your test project you define controls that represent (more or less) the actual controls in the page. These end up looking a lot like the ASP.NET user controls they represent and are easy to maintain. (Venturous uses a scoped seach within the parent element for the partial ID.)

Other frameworks support a similar pattern of pages and controls, but not quite as aligned with the Web Forms model.

Built in UpdatePanel support

Web Forms allows you to do “partial postbacks” using the UpdatePanel control. Using WatiN (or the other frameworks) directly, you would have to put some logic inside your tests to wait for the update panel to refresh. This makes the tests require more maintenance (someone added or removed an UpdatePanel in the application, and now the tests fail even though the functionality works for the user). Venturous will automatically handle the partial postbacks so you don’t have to think about it.

HTML element agnostic

With some frameworks you have to specify in the tests the type of HTML element you are working with. This ties the test to an implementation detail of the page markup. Venturous treats all elements the same so you don’t have to worry about it.

Server Errors throw exception

Venturous will check for server errors and immediately throw an exception containing the exception message from the error page. This makes it easier to see what the problem was with a failed test, instead of wondering why some element wasn’t found in the page.

Developer focused

Venturous is code and developer focused. Tests are written as unit tests in a regular unit testing framework. There is no record/playback GUI. This is a tool targeted at the developers working on the application under test so they can add WAT testing as part of their overall automated testing approach.

Opiniated API

The API surface is deliberately kept simple and specialized. Venturous is meant for writing happy-path feature tests that verify that user functionality works. It is not meant for detailed testing of validation errors, javascript behaviour or visual aspects. Therefore there is only the needed support for finding and interacting with elements, and only limited support for inspection. Tests should interact with other entrypoints of the system under test as needed, like web services, to arrange or assert persistent state.

No comments:

Post a Comment