angularjs - Return Promise Value from Page Object using TypeScript -
i'm trying return value webdriver promise within protractor solution using typescript, i'm getting undefined
response.
get nameinput(): string { var value: string; this.nameelement.getattribute('value').then(v => value = v); return value; }
in above case seems function not waiting promise return, therefore tried moving away getter style , declared return type webdriver's promise:
getnameinput(): webdriver.promise.promise<string> { var nameelement = element(by.id('name')); return nameelement.gettext().then(v => { return v }); }
but i'm getting function
return instead of value of v
. seems promise not being unwrapped jasmine's expect
, happens when running in js.
i know can run promise directly within expect, ideally create function's logic outside of expectations, can feed expectation function call (if any) parameters - instead of polluting test case promise logic.
any ideas?
you don't need resolve promises, return them:
getnameinput(): webdriver.promise.promise<string> { var nameelement = element(by.id('name')); return nameelement.gettext(); }
then need have real value returned getnameinput()
- resolve in test:
getnameinput().then(v => { console.log(v) });
note that, let expect()
resolve implicitly:
expect(getnameinput()).toequal("expected value");
Comments
Post a Comment