Protractor is an E2E test framework for AngularJS app testing. It is a Node.js program that works on top of WebDriverJS. Protractor was developed by the Angular team for testing Angular. It recognizes Angular’s processes and waits for them to complete. As a result, the browser “sleep” time is optimized and the tests run faster in Protractor testing.
Protractor Vs Selenium
If you visualize Selenium and Protractor diagrammatically, the protractor encapsulates all of the Selenium. Since Protractor is built on a Selenium base, all the functionalities of Selenium are also available for Protractor testing.
As you can see in the diagram, large parts of the functionalities of Selenium and Protractor are similar. But Protractor is also different in many ways from Selenium. One of the bigger differences is that Selenium interacts with a web page in a different manner when compared with Protractor. In Selenium, because of the way it interacts with the webpage, you have to wait or sleep many times in running automation. Selenium is not able to optimize the wait time for elements to appear on the web pages. Selenium requires the setting up of waits (Implicit and Explicit) so that automation can be synchronized. In case of wait is not programmed into an automation code, selenium will throw exceptions. In the case you are using an Implicit wait with Selenium, you can wait for the element. In case you are using an Explicit wait with Selenium, you can customize the waits to correspond with some expected conditions (elements to be clickable, elements to be visible, etc). You end up with lots of waiting based on what “wait” you program into the automation.
The protractor is very tightly coupled with AngularJS and therefore is able to optimize wait and reduce wait time. It also has commands like `browser.waitForAngular()` to wait until the cycle is done before continuing on. Because of these functionalities in Protractor, you can avoid waiting (Explicit or Implicit) for business logic to process.
In fact, Protractor automatically applies this command `browser.waitForAngular()` before every WebDriver action. For details on this please visit this page.
With Protractor testing, the test script runs using Node.js. The protractor runs one extra command before performing an action on the browser to make sure that the browser application which is being tested has stabilized. For example:
This will result in three commands being sent to the Browser Driver.
- /session/:sessionId/element – Then, the command to search the element is sent.
- /session/:sessionId/element/:id/click – Finally the command to “click” is sent.
Instruct the web driver to wait until Angular has finished rendering and has no outstanding $http or $timeout calls before continuing. Note that Protractor automatically applies this command before every WebDriver action. Please visit this page for further details.
Need help? Contact us now!