Is adding IDs to everything standard practice when using Selenium?

  • My team is using Selenium WebDriver and the QA team is having the developers add IDs to almost everything. Is that normal or is Selenium flexible enough that tests can be written with the markup that is provided without having to go back and add IDs? For example, if you have a list of similar items you would usually just use the same class for each item and not put a unique ID on each item in the list.

  • It's not unusual. IDs tend to aid greatly in creating more stable UI tests, since class name changes or other refactoring is less likely to break tests. Also, dynamically populated lists tend to be high-maintenance in UI automation, and having predictable IDs can help with that. Using XPath is not only slow, as squeemish pointed out (and slowness itself can break tests if there are any timeouts, which leads those tests being fragile), but XPath also tends to be more vulnerable to UI changes, again increasing test maintenance.

    Basically, your test engineers are probably finding that their test UI automation is fragile. This is a change from developers that can dramatically reduce test maintenance costs and, in turn, reduce the turn-around time on testing new builds. Fragility in UI tests is hard to manage, so other issues might also need to be resolved before you see the benefits of adding IDs.

Suggested Topics