I have a page with a button, which is being controlled by a backend job. once job completes => button gets enabled. user have to manually refresh the page to see the button enabled.
My Goal:
- Check if the button is enabled
- If the button is Enabled = exit the function and proceed to the rest of control flow
- If the button is NOT enabled, wait 10 seconds and refresh the page to check If the button is Enabled, and so on
- Do not go over 10 iterations of waiting. if the button is still not available - exit the function and fail the test
I'm using Protractor with JavaScript
here is what I have so far:
----------my control flow-----
it ('waiting for button', () => {
itTopicReg.waitForBtn();
});
---------my help script from itTopicReg--------
proceedToQaBtn = element(by.buttonText('Proceed to Qa Environment'))
nIntervId = null
waitForBtn() {
this.nIntervId = setInterval(this.isBtnEnabled(), 10000);
};
isBtnEnabled() {
let count = 0;
if (this.proceedToQaBtn.isEnabled()) {
expect(this.proceedToQaBtn.isDisplayed()).toBe(true);
} else if (count < 10)
count++;
browser.navigate().refresh();
} else if (count >= 10) {
clearInterval(this.nIntervId);
};
I get the following error:
✗ waiting for button
- Failed: "callback" argument must be a function
at exports.setInterval (timers.js:411:11)
at ItTopicReg.waitForBtn
I'm new to Protractor and to JavaScript, pardon if that's something obvious I've searched here and have not found resent clean solution (like Protractor : wait for element to become invisible/hidden or Refreshing page until element appears - JAVA - Selenium)