protractor icon indicating copy to clipboard operation
protractor copied to clipboard

ElementFinder.prototype.then not returning a promise

Open Ferengee opened this issue 12 years ago • 4 comments

I would expect every .then call to return a promise. Since the protractor test below passes, ElementFinder's then method clearly returns the return value of the succes function.

When reading the documentation: https://github.com/angular/protractor/blob/master/docs/api.md#elementfinderprototypethen I get the impression that it should return a promise (or a then-able)

Maybe this is a design decision, if so I would like to know the reason. On a side note: I am very happy with protractor and I enjoy seeing the progress it makes. Thanks

Protractor test on version 1.0.0

describe('ElementFinder.then', function() {
  var fqdn = browser.params.fqdn;

  beforeEach(function(){
    browser.get('http://' + fqdn);
    browser.ignoreSynchronization = true;
  });  
it('should always return a promise', function(){
    var e1 = element(by.tagName("body")).then(function(){});
    expect(e1).toBeUndefined();
    //expect(typeof (e1.then)).toBe("function");

    var e1 = element(by.tagName("body"))
    .then(function(){return protractor.promise.fullyResolved({});});
    expect(e1).not.toBeUndefined();
    expect(typeof (e1.then)).toBe("function");
  });

});

Ferengee avatar Aug 04 '14 13:08 Ferengee

@hankduan we should probably wrap the returned function as an immediately-resolved promise. Can we do:

  ElementFinder.prototype.then = function(fn, errorFn) {
    if (this.opt_actionResult_) {
      return this.opt_actionResult_.then(fn, errorFn);
    } else {
      return webdriver.promise.fulfilled(fn(this)); // Change this line?
    }
  };

juliemr avatar Aug 04 '14 17:08 juliemr

fixed in https://github.com/angular/protractor/pull/1158

hankduan avatar Aug 04 '14 23:08 hankduan

committed with https://github.com/angular/protractor/commit/d15d35a82a5a267bb7ae9c675017f091901c019f

hankduan avatar Aug 05 '14 17:08 hankduan

Thanks for a very quick response

Ferengee avatar Aug 06 '14 06:08 Ferengee