Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing Angularjs with Selenium without element id

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

like image 844
PSWai Avatar asked Aug 16 '13 14:08

PSWai


People also ask

Can Selenium be used to test AngularJS applications?

Selenium API has implementations in several major programming languages - allowing you to write your tests in Java, C#, python, ruby, JavaScript and more. If you already have a selenium-based e2e testing framework in place - you can use it also for AngularJS web-apps.

How do I use ngWebDriver?

To use ngWebDriver in selenium all you need to do is just add the maven dependency from mvnrepository (https://mvnrepository.com/artifact/com.paulhammant/ngwebdriver) to your pom. xml file as shown below.

Can you test JavaScript with Selenium?

Selenium is an open-source automation testing tool that supports a number of scripting languages like C#, Java, Perl, Ruby, JavaScript, etc. Depending on the application to be tested, one can choose the script accordingly.


1 Answers

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

like image 174
Zane DeGraffenried Avatar answered Nov 14 '22 17:11

Zane DeGraffenried