Special Attributes for Automated Testing
This was a discussion we had at work. I’d love to hear other perspectives!
A little context: https://techblog.constantcontact.com/software-development/a-better-way-to-id-elements-in-selenium-tests/
One of the biggest maintenance issues with automated testing is having to constantly update the selectors we’re using in our automated tests. It’s cool, things change in the apps and so an element that used to have an id assigned no longer does. Or a class name changes as we evolve the structure & styling in Harvest.
One example of this is the primary nav within Harvest – I’ve had to update the selectors on this a few times, currently it’s looking at an element at a set position within the list of links – but what if the class names changes, we re-order the list, put the links in an ordered or unordered list or start using a button instead of an a element?
Looking at ways to cut down this maintenance cost (in terms of the time spent just updating locators in tests) the article above looked promising. The gist of it is that we’d put in special attributes on elements in the apps that we can use as static selectors.
<a class="primary-nav-item" href="/expenses">Expenses</a>
<a class="primary-nav-item" href="/projects">Projects</a>
Would become:
<a class="primary-nav-item" data-qa="main-nav-expenses" href="/expenses">Expenses</a>
<a class="primary-nav-item" data-qa="main-nav-projects" href="/projects">Projects</a>
Are there any concerns to this approach? I’m looking to the expertise of our accessibility gurus here about whether this would cause issues that you can see? Or any other concerns if I were to throw a few of these in to Harvest to test the waters in areas that are currently difficult to maintain the tests?