Image Blog ALM Prep Web App
March 13, 2015

5 Tips to Prep Your Web App for Automated Testing

Test Management
Application Lifecycle Management

Why Automated Testing for Web Applications?

Automated testing is essential for web application development. It's a type of software testing that helps you test more code and elements faster, so you can release your web app on time. 

But automated testing goes much more smoothly when development writes code with QA in mind.

How to Code a Web App for Better QA

Want to win the hearts of your quality assurance team? Make it easier for analysts to quickly create more accurate, repeatable automated tests.

Simply follow these five tips.

1. Be Specific in Your Code

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

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. Code for User Experience

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 Code for Unexpected Behavior...

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. Use Reasonable Limits for Lists

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. Make It Easy to Reset Your App

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.

Bring QA and Development Together

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.

Looking for more automated testing tips?

Get Best Practices for Automated Testing

This blog post first appeared on SD Times.com.