Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

ElementFinder.prototype.then not returning a promise #1152

Closed
Ferengee opened this issue Aug 4, 2014 · 4 comments
Closed

ElementFinder.prototype.then not returning a promise #1152

Ferengee opened this issue Aug 4, 2014 · 4 comments

Comments

@Ferengee
Copy link
Contributor

Ferengee commented Aug 4, 2014

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");
  });

});
@juliemr
Copy link
Member

juliemr commented Aug 4, 2014

@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?
    }
  };

@hankduan
Copy link
Contributor

hankduan commented Aug 4, 2014

fixed in #1158

@hankduan
Copy link
Contributor

hankduan commented Aug 5, 2014

committed with d15d35a

@hankduan hankduan closed this as completed Aug 5, 2014
@Ferengee
Copy link
Contributor Author

Ferengee commented Aug 6, 2014

Thanks for a very quick response

@hankduan hankduan removed their assignment Nov 4, 2015
bodyduardU pushed a commit to bodyduardU/protractor that referenced this issue Dec 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants