Got Promise { <pending> } inside a do while loop
Hi I am very new to Javascript async await I am trying to do mobile automation and I need a do while loop to swipe if the element does not exist. however I am getting Promise { <pending> } when calling a function inside the loop. I believe that I need to resolve the promise in order for me to get the actual result. I've tried to search forums but no luck in finding the solution. I hope this is the correct forum. Please see the code below:
This is the function to check if the element exist:
async isExist(locator) {
return this.client.isVisible(locator);
}
And this is my loop:
async searchElement(locator) {
let lookForElement;
let limitCounter;
do {
lookForElement = this.client.isVisible(locator);
limitCounter = this.client.isVisible(locator);
if (lookForElement === false) {
this.swipe(81, 700, 81, 682);
this.pauseForInSeconds(0.7);
} else {
this.clickOn(locator);
break;
}
} while (limitCounter === false);
the issue is lookForElement and limitCounter will return Promise { <pending> } it will be solved by appending await in this.client.isVisible(locator); function but ESLint will detect an await inside a loop. maybe someone could help me with this matter. Thanks alot.
Just disable the rule with so-called "eslint disable comments".
// eslint-disable-next-line no-await-in-loop
lookForElement = await this.client.isVisible(locator);
// eslint-disable-next-line no-await-in-loop
limitCounter = await this.client.isVisible(locator);
Check out the ESLint docs here for more info. :)
@michaeldeol for one, this isn't a general JavaScript help forum, it's a repo for Airbnb's JavaScript style guide (which discourages loops).
It also forbids async/await entirely.
I'd suggest StackOverflow, or IRC, for generic JS help questions.