Performing odd jobs with Selenium helper pages

Selenium [1] is a nice tool for testing browser based user interfaces. It’s simple to install and with the firefox IDE plugin, it’s even easier to use. But there are some tests that are just not accessible through a UI. Should you even test functionality that’s not immediately expressed, and if so how?

Before I go any further it’s important to identify Selenium place in the testing food chain. Selenium is a great tool for acceptance testing but it’s not intended to replace unit testing. Rather Selenium should be used in conjunction with unit testing.

Having set the stage, let me focus on using Selenium. I’m personally of the opinion that anything that can be tested should be tested. The hard part is figuring out how and making it cost effective.

The problem
In most applications there comes a point where the functionality that needs to be tested is not immediately accessible in the UI. Examples of this include:

  • Pre-populated datasets. In order to fully test the changing status of different items, workflow through a system, or reporting functionality, you may need a number of pre-populated data items. This is often a sample dataset of a complete or partial transaction.
  • Bulk addition of test data in different states. You may have an object that can logically be in different states. One approach to testing this efficiently is to populate the database with objects in each of those states.
  • Date rolling. Dates often affect how data is processed, and it may be necessary to roll the date forward to fully test this functionality.

A Selenium solution
How is this achieved with Selenium? The engineers at my current client came up with a simple strategy; construct a Test-Helper page.

A Test-Helper page is a simple JSP page that contains links to the necessary functionality. The test helper page simply sites alongside the main application. Whenever the acceptance tests need to invoke a helper function, Selenium navigates to the helper page and invokes that function.

This is a simple yet elegant solution to the problem. It avoids any complexity of extending Selenium, but at the same time allows richer testing of the underlying functionality via the UI.

A note of caution: Take care to not to include helper pages in a released and/or deployed product. Helper functions may be useful for testing, but in a production environment their very nature may expose all manner of risks.

Bookmark and Share

References
[1] Selenium home page

Comments are closed.

Follow

Get every new post delivered to your Inbox.