Protractor and Promises
So recently I have started to use Protractor to test my AngularJS code. I created a little library to helper be with creating page/component object which I use to test with. One of the methods I created returned a promise and was expect to be used with an assertion however it was not working properly. I was using bluebird to generate by promise as I do with most of my NodeJS code however I found out that when dealing with promise, protractor expects WebDriver promises.
So instead of creating promises like this:
var defer = bluebird.defer();
you need to create promises like this:
var defer = protractor.promise.defer();
Everything else expect one things works as expected. I found out that the WebDriver promises does not exposed a resolve()
method. After looking at the source code a little, I figure out that I needed to use the fulfill()
method.
If you create code the returns a promise with Protractor and you want to use the promsie in an assertion, make sure the you create a WebDriver promise.