March 13, 2015

5 Tips to Prep Your Web App for Automated Testing

Test Management
Thanks! Want to win the hearts of your Quality Assurance team? Remember these 5 tips when working on your web application to make it easier for analysts to quickly create more accurate, repeatable automated tests.

1. Ambiguity is the enemy

Be as specific as possible in your code. Of course, you’re already following W3C standards, right? Here are three things you can do to avoid problems in automated tests:
  • Use meaningful names and IDs for elements. Auto-generated IDs aren’t always intuitive and may change every time a page loads. For example, setting the username edit box on a login page to something like ‘loginUserName’ makes it easy for analysts and automated testing tools to identify the field.
  • Use IDs on <body> tags to differentiate content for pages that share the same URL, such as pages that use Dynamic HTML or AJAX.
  • Follow CSS standards. Classes and IDs are not the same thing, so don’t use them interchangeably.

2. There’s more than one way

Support any alternate ways a user can interact with an element. For example, if hovering over an element opens a flyout menu, support a click to open the menu too. Automated testing tools handle clicks much more gracefully because they rely on a specific action instead of timing. Plus, it’s always good practice to anticipate other ways that users may choose to interact with elements.

3. Don’t use a hammer to drive a screw

Get rid of unexpected behaviors on elements. For example, let a link be a link. The expected behavior for an <a> tag is to navigate to a different page. If you add an onclick handler to the <a> tag and navigate from the onclick, you’re deviating from the expected behavior of the link. If you’re navigating with the link, the href attribute is sufficient and expected. If the link doesn’t navigate, a different tag, such as <span> or <div>, is more intuitive.

4. Cut back on the noise

Use reasonable limits for the number of items in objects, such as lists and combo boxes. Don’t clutter lists with unneeded or large numbers of values. After all, it’s good UI practice and it reduces the likelihood of ambiguity and performance issues in automated tests.

5. Save the environment

Make it easy to reset your application to a known state. This way, issues can be consistently reproduced in the application until a fix is applied. For example, if a login issue is found during regression testing, there are likely clear steps to reproduce it. If the application remembers the login and there is no way to reset it, you can’t reproduce the issue. Unknown environments can also lead to false positives and negatives during testing. If the application cannot be reset to a known state and a test passes, the test may incorrectly pass because it does not always have the same starting point. If a test fails, it’s more difficult to determine if it is because of the state of the application or if there is an actual bug, which decreases the value of automated tests.

Everybody wins

Following these five tips will help you create a win-win situation for your entire development team. It’s a win for QA because analysts can quickly create more accurate, repeatable automated tests. They can also focus on testing new features because they’ll have a more reliable automated suite. As a result, your application development lifecycle will be streamlined because automated testing is doing the heavy lifting—and that’s a win for everyone. This blog post first appeared on SD Times.com.