Best practices for developers to increase testability of web apps for QA?
I'm writing a document for a developer at my company who will be working on a web app. Here's the advice I have for him so far (below). Can any of you think of more that I can add? Not sure which tool we'll be using, but Selenium and WatiN are strong contenders.
- Web elements should be:
- a. Uniquely identifiable - Selenium prefers id (fastest for looking up elements)
- b. Ideally, human-friendly, e.g. firstName instead of input82347
- Favor standard web elements like
over many layers of nested
for the UI
- Class names and other element attributes should not be repeated unless it makes sense, e.g. don't use the same class name for functionally different components (cheesy example: both
having the exact same class name)
- Selenium doesn't like compound class names (e.g.
4 and 5 on your list don't seem necessary and may actually be counter-productive. Selenium does fine with compound class names, and it would actually be extremely difficult in terms of CSS/presentation to restrict it that way. If the classname is not unique and maybe even if it is, give it an ID (which is the fastest way for an element to be found via selenium).
Another thing that I run into a lot would be dynamically generated elements, usually in a list (like messages in an e-mail inbox, or list of saved something). Working with them may be difficult since there can be varying numbers of them, with varying text. The easiest way to work with these elements is generally to give the parent element a unique identifier and then get a list of all of the child elements using xpath.