Peter Morlion logo


ngEurope: Protractor

At ngEurope, Julie Ralph and Chirayu Krishnappa gave an interesting presentation on Protractor. Protractor is a framework for end-to-end testing. The goal was not unit testing, because unit testing won’t catch everything. Like so many of the projects in the Angular and javascript space, it is heavily under development, but the 1.0 release is planned for July 2015.

Protractor is implemented in NodeJS so you can write your tests in javascript. The most common way to run them is to use a local Selenium server. Tests can run in parallel and the primary syntax is the Jasmine syntax (with describe, beforeEach, it,…).

Protractor exports some globals to interact with the DOM. This is an example of getting the element that is data-bound (with Angular) to ‘name’ and entering some text:

element(by.model('name')) // get the <input ng-model="name" /> element
    .clear() // remove any text
    .sendKeys('abc'); // enter 'abc'

You can of course also search by id, class,…

Protractor includes filtering, clicking, setting text, and much more. As this is all done in javascript, you can (like in any other programming language) structure your code so you can reuse certain objects across different tests. An example could be a block of code that handles logging in.

Finally, it’s important to note that Angular uses Protractor for its end-to-end tests, but the Protractor API is agnostic to Angular.

The session was short but it was enough to raise my interest. UI testing has always been hard, both in building tests and maintaing them. I’d have to test Protractor to see if it is any better, but I’m optimistic.

Leave a Reply

Your email address will not be published. Required fields are marked *