Unidentified web objects
A bane to automated testing for web applications is having to test an object or page element that is not uniquely identifiable. I've run into this issue on several different projects and with different test automation tools, and have not found a general practice that will get around it. There may be specific hacks that get around a specific case (such as having to always select the 7th checkbox in a list, for example), but not in general.
This issue comes in several flavors, such as:
- Multiple elements on the same page with the same identifier information.
- Elements on a page with no specific identifier information.
- Identifier information changes each time the application is run.
With QuickTest Pro, the result is often a failure to find the object, or an error message saying that multiple objects were found, and the tool has no basis to choose between them.
I ran into the first flavor today with a custom heirarchical menu that had three items (hidden under different parts of the tree, but still visible to QTP's descriptive programming) with every property identical exceept location on the page. To get around it I would have to write some very specific, fragile, custom code to find a list of objects and pick the right one based on relative coordinates.
I suspect that this is not an issue that any test automation tool is going to be able to fix. The testing phase is too late to fix this issue. It has to be fixed during development.
What is needed is a tool to analyze a web page during development, and flag any page elements that are not uniquely identifiable or persistent. This would then become a work item in the IDE similar to compile errors or code analysis errors. Such a tool should be enabled in IDEs and including in the build tools and should cause a build to fail if for any issues not marked ignore. It would enable every build to be testable, as every element of every page would be identifiable (ignoring some element types of elements that are not tested, such as static text labels).Fortunately HTML provides a simple mechanism for creating a unique identifier on a web page, the "id". Unfortunately, most developers and most web development tools do not use it or check for it. A tool that did would make the test engineer's life much easier.