Reputation: 1188
Our team is working on a web app with AngularJS. For testing, we use Jasmine for unit testing and angular-e2e testing. That works fine. However, our QA team approached us today that they tried to use selenium for testing the web app but facing problems as we are not defining IDs for most DOM elements. We have researched a bit on this but no luck. May someone suggest a good way to do selenium test without having us to explicitly add in all the ids just for the use of selenium? Thanks!
Update
We have some meetings and ended up inserting ids to elements for robustness in testing. Thanks everyone for answering :)
Upvotes: 6
Views: 6707
Reputation: 15423
We have encountered the same situation in our work now. As mentioned in this discussion, we compared the possible two approaches to overcome this issue:
We decided to go with (2) and add IDs where needed. Tests robustness in much better and the overhead is not significant at all.
What we did exactly? To the relevant elements, attribute named data-hook
was added with the proper value that identify him. Works great.
Upvotes: 2
Reputation: 113
If you are using Selenium WebDriver there are many ways to find elements on a page. XPATH is probably one of the better approaches as far as flexibility goes (though it can get ugly quickly) but WebDriver also allows you to use Class Names, Tag Names, Name, Link Text and CSS.
Selenium WebDriver - Locate UI Elements
Upvotes: 5