Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

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 :)

share|improve this question
1  
This is possible yes, see below answer. However, be aware that tests built using xpath or css-selectors will be more fragile that those built with proper unique IDs for the elements. – Mark Rowlands Aug 16 '13 at 15:53
    
Thanks for the note! So is it better that we introduce unique IDs for all elements in this case? Currently there are two thoughts in our team that one, we shouldn't be altering the app that much (by introducing lots of IDs) just for a supporting tool; two, introducing IDs is not that hard nor destructive, if it solves the problem then why not. Both thoughts sound reasonable to us, which would be the better way in this case? – PSWai Aug 17 '13 at 2:19
up vote 4 down vote accepted

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

share|improve this answer
    
Thanks for pointing it out! Personally I've no experience with Selenium WebDriver so I'm not very sure of this, I'll approach our QA team again on this :) – PSWai Aug 17 '13 at 2:22

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:

  1. Try and locate the elements differently.
  2. Introduce IDs where needed, even though they not required by Angular development.

We decided to go with (2) and add IDs where needed. Tests robustness in much better and the overhead is not significant at all.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.