Protractor: test AngularJS from user’s perspective

Protractor: test AngularJS from user’s perspective

AngularJS is one of the most productive JavaScript frameworks and one of the main advantages is its approach to the testing. Testing was deemed so important that it was built into AngularJS. The main aim is to catch errors before they happen in production. Special attention is paid to the end-to-end testing. It checks whether the system works as planned from an end user’s viewpoint.

End users want the application and its features to function properly. It would be time (and, in many cases, money) consuming to click through the application manually, so writing tests is the best solution. End-to-end testing automates processes of starting the app in a browser and clicking through the workflow of the application.

Protractor is an open source end-to-end test framework. It is the preferred tool for testing AngularJS-based applications.

Protractor is built on top of Selenium’s WebDriver that is responsible for controlling browsers. WebDriver is an API, written as extensions that support different browsers. Developers receive fast and stable tests by running them against real web browsers and headless browsers. WebDriver provides native events and browser-specific drivers so that interaction with the app is similar to the one users would expect. There is also option to apply some drivers that implement WebDriver's wire protocol, like ChromeDriver and GhostDriver.

Protractor is built atop the Node.js framework. It can be installed as a standalone test runner or embedded in tests as a library. Moreover, Protractor supports behavior driven development (BDD) test frameworks such as Jasmine, Mocha, and Cucumber. They provide additional syntax, scaffolding, and reporting tools which can be useful for better test writing and managing. Basically, by combining these powerful tools and technologies Protractor works as a solution integrator.

Protractor features automatic waiting. It speeds up the testing by optimizing sleep and wait times. There is no need to add waits and sleeps manually. The framework will automatically execute the next step in the test after the webpage finishes pending tasks. Protractor also has support for Angular-specific locator strategies (e.g., binding, model, repeater) and native WebDriver locator strategies (e.g., ID, CSS selector, XPath) that provide an out-of-the-box testing of Angular-specific elements.

Protractor allows you to write both unit and functional tests, as well as to run them against application in a real browser, interacting similarly to end users. Its aim is to cover the acceptance criteria required by the user. For more information see Protractor home page.

Follow