Skip to content

Instantly share code, notes, and snippets.

@felippenardi
Last active August 29, 2015 14:21
Show Gist options
  • Save felippenardi/4aad9dffb3d207289fb2 to your computer and use it in GitHub Desktop.
Save felippenardi/4aad9dffb3d207289fb2 to your computer and use it in GitHub Desktop.
Writing AngularJS Protractor Specs

Writing AngularJS Protractor Specs

When writing protractor tests you will be dealing with two libraries:

Jasmine Methods

The Jasmine syntax is the same used on unit tests: beforeEach(), describe(), it(), and so on

WebDriver Methods

When running end-to-end with Selenium, you are controling a real browser. The methods specifcs to the webdriver will do all sort of browser interaction, such as: going to an URL, refreshing the page and so on. But for Angular applications, it is important that Selenium respect Angular timing: by waiting for it to render. For this reason, Protractor has a set of methods under the object browser that wraps the main Selenium functionalties and make it work better with Angular.

You will not be using Selenium WebDriver methods, but Protractor's browser object instead.

Protractor Methods

When writting end-to-end tests for Angular, it is difficult to tell when the application is done with updating the scope. That is why the Angular team created Protractor: to give you a simple way to test values without worring about digest loop.

Using protractor, you can interact with DOM elements as usual in a end-to-end test, but you can also retrive scope values with easy.

The main difference between unit tests and Protractor Methods is that Protractor's return promises. You define which scope value you want to retrive with the method element(by.binding('scopeValue')). Then, whenever the Angular app is finished with digest loops, Protractor solves the promise with the last scope value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment