Alex Rivera | Logout

Automated GUI Testing: Meeting Us Halfway

Asked 2009-05-04T21:55:18.193
10

I've been tasked with developing a system for automated GUI testing and I could use some advice. As luck would have it, we are in the midst of a major redesign of our GUI and the developers doing the work are open to making their code more friendly to automation. My problem is that I'm not sure what to ask them to add. Whatever hooks are added can't impact the functionality, appearance or security of the interface and shouldn't have a noticeable impact on performance. Other than that, the sky's the limit!

The application in question is a web-based Java app accessed via AJAX. Most of the existing features are coded using jsp, Javascript and a little bit of Flash 8. The next wave of features will be done using the YUI Javascript library. I'm pretty much settled on Selenium as a test tool because of its flexibility and price tag (free). Major point: I'm aiming for test-reusability and ease-of-maintenance. My preference is to write code that detects, validates and exercises the page elements rather than use a record-and-playback system for test development.

Can anyone provide some guidance as to what hooks could be placed in the code or some best practices to make test development easier and the tests themselves more robust?

Edit
Report

2 Answers

5

As with most questions, it depends. Mostly on what your site looks like and what sort of controls are on the pages - are there a lot of repeated elements etc?

I've had a lot of success using Selenium RC and Selenium IDE. The main thing is getting used to using Selenium and its commands. It's also helpful to get used to locating objects on the page (XPaths and CSS selectors, as well as 'contains' function). What you don't want is a lot of elements that have the same select path. If the tables and divs below don't have a unique part to them, it can add extra complexity to your tests.

<html>
  <body>
    <table>
      <tr>
        <td>
          <div></div>
          <div></div>
          <div></div>
        </td>
      </tr>
    </table>
    <table>
      <tr>
        <td>
          <div></div>
          <div></div>
          <div></div>
        </td>
      </tr>
    </table>
  </body>
</html>

To test images, its nice to be able to check for their existence based on something other than the image file name, so you don't have to change your tests when the image is updated. If you need to test Flash objects, check out this site.

Beyond that, there isn't a whole lot that I have noticed that can be incorporated in the development side. Once you start setting up the tests and locating elements on the page, you'll probably see pretty quickly what the developers need to do to help you out.

answered 2009-05-04T22:44:04.817
5

One piece of advice: keep your test code in at least two layers of abstraction:

  1. upper layer: this should be some sort of a facade that is oriented towards your specific application terminology/actions etc. This layer does not directly use the Selenium RC library. In the background it uses the...
  2. ... lower layer: a library with some common testing patterns (example: "assert that the value X of the radio button control is chosen"), which uses the Selenium RC library.

This way your tests will be cleaner to maintain and more understandable in terms of what is being tested. We even tried a three-layered approach, the third (uppermost) layer being the tests specified using XML. This was in order for our non-programming testers to be able to specify acceptance tests without delving into the C# code.

answered 2009-05-05T19:34:19.913

Your Answer