Struggling to retrieve a value from a WebDriver promise in a Protractor solution using TypeScript, the response keeps coming back as undefined
.
get nameInput(): string {
var value: string;
this.nameElement.getAttribute('value').then(v => value = v);
return value;
}
In the current scenario, it appears that the function is not properly handling the timing of the promise resolution. To address this, I attempted to refactor the code by changing the return type to WebDriver's promise:
getNameInput(): webdriver.promise.Promise<string> {
var nameElement = element(by.id('name'));
return nameElement.getText().then(v => { return v });
}
However, the return value is showing up as Function
instead of the actual result stored in v
. This issue seems to be related to Jasmine's handling of promises, which behaves differently compared to running the code in JavaScript.
While I understand that executing the promise directly within the expectation may work, my preference is to separate the logic into standalone functions and pass them to expectations without adding promise-related complexity to test cases.
Any suggestions or insights on how to tackle this?