In my Angular app, I am writing the automation test suites of the application using Protractor, and I faced with problem how to test spinners, to wait for the spinner to disappear from the screen. I have tried to create some reusable function for handling spinners, and look like it works fine, but when spinner is located on popup window I received error: "... Failed: stale element reference: element is not attached to the page document...", as I understand protractor couldn't find specified element, because after closing popup window, spinner removed from DOM with popup. In my function I have tried to use this protractor methods: browser.wait(EC.invisibilityOf($('#abc')), 5000); browser.wait(spinner.isDisplayed(),5000); As I understand the reason is that browser.wait runing in the loop inside condition until it comes true or timeout occurs, but I don't know haw to fix it. Please help ...
My lust function with additional checking for presents: this.selector - parent element (button)
waitBtnSpinner() {
let spinner = this.selector.element(by.css('.btn-spinner'));
spinner.isPresent().then((isPresent) => {
if(isPresent) {
spinner.isDisplayed().then((isDisplayed) => {
return browser.wait(this.EC.invisibilityOf(spinner), 10000);
})
} else {
return isPresent;
}
});
};