Why can't we use Selenium Webdriver to test Angular JS sites?
emmalee last edited by
If we look at the Protractor architecture, Protractor uses WebDriver JS to call Selenium Webdriver which ultimately calls browser driver and then browser. Now since Selenium is passing commands to browser driver why can't we just use Selenium to automate Angular pages ?
I do use Webdriver to use Angular pages. So it IS possible, and OP's assumption is wrong.
But it is not easy - not as straightforward as using WebDriver to automate more traditional web pages (which do not use "single page application" concept and DOM manipulation so heavily), where is trivial to add id or name to any element you want.
Angular uses IDs heavily for interaction and DOM manipulation. As a result, WebDriver tests cannot rely on IDs to locate elements, and locating by name is bit more hassle (non-unique etc). But you can still write tests using WebDriver (that's how Protractor does it after all, under the skin).
WebDriver tests are Angular-agnostic, they know nothing about Angular and the complicated machinery on the page it uses to manipulate DOM.
Protractor understands Angular and this allows developers to write Protractor-based tests bit easier - and as always, for the price.
Edit (April 2018): Angular2+ is a significant if sneaky change over AngularJS. Angular2+ does not support some AngularJS-specific locator strategies anymore (and has no plans to implement them), so there is even less incentives to use JS (beyond JS unit-tests of Angular stuff). So when talking/reading about "the Angular" you need to be aware of which version we are talking about, they are significantly different.
Our current strategy is to implement Angular2+ unit-tests (model, basic manipulation), and also single happy-path UI test in JS. More comprehensive UI tests will be in Python/WebDriver. Yes, it is slight duplication of work (locators are both in JS and Python, but locators are trivial). We prefer Python, have lots of code in it, including testing tools/fixtures, which are easier to call from Python than from JS, so we think it is the best compromise.
That is why I asked OP about any hands-on experience. For any person with hands-on experience with writing both WebDriver and Protractor tests, it is a matter of taste and preferences.