Test IDs for Test Automation in HTML Markup?
automated-tests, html, integration-testing, testing, web-applications
Solution
I'd say the benefits of easier and better testing outweigh the perceived risks. I assume you are talking about something like the following: adding id='resultDetail' to a result detail element on your page so that it is easier to find for the automated test. I frankly don't see the harm in that. If I am taking an overly simplistic view, perhaps you could throw up some sample markup to give us a better idea of what you are considering.
Having seen your sample markup, I don't see any problem with having the id available to the user. Many applications expose domain ids. As a matter of fact, in my experience, often those domain ids are an integral part of the UI - often ids will be links that you can click on to get more detail, to edit, delete, etc...
Problem
We use automated tests to verify functionality of our web application. In order to make assertions in test cases less complicated and more flexible, we are considering the introduction of 'TestIDs', i.e. IDs in the HTML markup that help testcases find and verify elements on the page. Additionally, these TestIDs would allow more specific integration tests which are currently impossible due to the limited data on the pages. However, here is what makes us hesitate: - introducing test IDs means changing the tested for testing - security - we would disclose internal domain object IDs and other information that would otherwise not be visible on the page - standards - depending on how we put the TestIDs into the markup we would most likely violate the intended semantic use of an element or attribute (e.g. 'id' or 'class' attributes, other html elements, etc.) - interference - TestIDs could interfere with application code - performance - TestIDs are unneccessary markup (to the user) and increase page size (only significant on large pages) Limiting TestIDs to test/staging HTML doesn't seem to be a good idea because we obviously want to test code that will be used in production and don't want our test/staging environment to behave differently. In fact, we currently run parts of our test suites against the live system after a release. Do you think TestIDs are a good idea and if so how would you put them into the markup? Some sample markup to demonstrate what I'm talking about: ``` <!-- this test id allows an integration test to verify that the carrot 188271 is in fact green but exposes the id to the user --> <tr id="testid-carrot-id-188271"> <td class="color">green</td> <td class="size">doesn't matter</td> </tr> ```