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>