Creation
For creating a promise in protractor, you have to write:
var deferred = protractor.promise.defer();
var promise = deferred.promise;
Callbacks
The callbacks are invoked asynchronously.
You can register one (or more) "on success" callbacks:
promise.then(function() {
...
});
you can also register one (or more) "on error" callback:
promise.then(null, function() {
...
});
These registrations could be chained:
promise.then(function() {
...
}).then(function() {
...
}).then(null, function() {
...
}).then(function() {
}, function() {
...
}).then(onSuccess, onFailure);
Resolution
Success
The "on success" callbacks are invoked when the promise is resolved successfully:
deferred.fulfill(value);
Failure
The "on failure" callbacks are invoked when the promise is resolved successfully:
deferred.reject(new Error('a problem occurs'));
In your code
you missed the resolution step. You have to fulfill the promise.
A more complete reference is available in the Webdriver.js documentation
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…