Protractor is an end-to-end test framework for Angular applications built on top of WebDriverJS.
I am new to the field of web testing, and I am trying to figure out what are the advantages of using Protractor, instead of using directly WebDriverJs. What is the added value of Protractor?
Protractor is an end-to-end test framework for Angular applications built on top of WebDriverJS.
I am new to the field of web testing, and I am trying to figure out what are the advantages of using Protractor, instead of using directly WebDriverJs. What is the added value of Protractor?
Share Improve this question edited Nov 19, 2022 at 1:08 Peter Mortensen 31.6k22 gold badges110 silver badges133 bronze badges asked Oct 18, 2013 at 20:58 cateofcateof 6,75825 gold badges85 silver badges155 bronze badges3 Answers
Reset to default 16 +50The added value of Protractor is that Protractor knows about Angular. This has some advantages like:
- You do not have to build in wait statements to wait for Angular processing because Protractor knows when Angular is still busy and waits for it.
- You can add extra selectors on things like Angular bindings, Angular repeaters, etc.
Protractor does a number of things that are really helpful. They're all based on the ideas that Edwin brought up. Protractor knows that the app you're testing is an Angular app, so it knows you're using certain services and so it'll actually load those services in and watch them for you.
For example, in a typical end-to-end test (using WebDriverJS or some other framework) you have lots of waits/sleeps. You click a button that requires an Ajax request and then you have to put in a 3-4 second sleep to wait until that Ajax call returns. Well, in Angular, all Ajax requests are (or should be) done using the $http
module. Protractor watches the $http
module and automatically adds in sleeps for you while your requests are pending and your page is rendering. So you no longer have to guess how long a request is going to take and then you don't have to worry about your tests failing because a request took too long.
It also allows you to find elements based on things like the input's ng-model
or by {{bindings}}
on the page or by an ng-repeat
element so that you can easily and quickly find the elements that you want to test.
Julie actually explains why she developed Protractor over using WebDriver in this video and she answers this very question at the end during the Q&A session (though the quality of the video is pretty rough so it can be annoying to watch).
If an application is developed on AngularJS, using Protractor to test it will be a benefit.
This is because,
Protractor is an end-to-end testing framework for AngularJS applications and works as a solution integrator - bining powerful tools and technologies such as Node.js, Selenium, webDriver, Jasmine, Cucumber and Mocha.
It has a bunch of customizations from Selenium to easily create tests for AngularJS applications.
Protractor also speeds up testing as it avoids the need for a lot of “sleeps” and “waits” in your tests, as it optimizes sleep and wait times.
Protractor allows tests to be organized based on Jasmine, thus allows writing both unit and functional tests on Jasmine.
It runs on real browsers and headless browsers.
Allows running tests targeting remote addresses
And also we AngularJS has its own locator which like model, repeater, binding which can be easily understood by protractor to identify the objects.
Conclusion
Protractor is neat – and we see it as a very useful evolution from Selenium Webdriver for JavaScript.
It’s not limited to testing only AngularJS apps – even though these two are usually mentioned together. However - it was designed mainly for Angular and some work is required, at least currently, to use it on non-angular pages.
If you plan to gradually move your site/app to Angular - you can start writing your Protractor E2E tests right now.