Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor on AngularJS - 'script timeout: result was not received in 11 seconds' after login page change

Protractor hangs completely when trying to get any element property after logging in (idk if it's related to logging in or related just to switching pages).

it("Should get location of main container", async function() {
    await LoginPage.validLogin();
    // Works and logs in the dashboard
    await browser.sleep(3000);
    // Get the main container by class name
    const container = await element(by.css(".main-container"));
    // Logs properly the element functions (as expected)
    console.log(container);
    console.log(await container.getLocation()); // Hangs here
});

In this case, I'm trying to get the location of the main container element on the page. The first console.log fires and shows properly, while the second hangs completely, so I get the script timeout. Increasing the timeout time doesn't help at all...

I found online that misusing $timeout in AngularJS instead of using $interval may lead to this strange behaviour, but I really can't skim through the entire (very big!) project's codebase to change everything hoping that it just works, not to talk about the external libraries using $timeout.

I have SELENIUM_PROMISE_MANAGER = false; in my Protractor config so I disabled the built-in Control Flow in order to manually manage the promises using async/await, but even if I use the built-in Control Flow without using async/await I get the very same behaviour and error. I'm using Jasmine as testing framework.

Maybe I'm missing something? Any help would be much appreciated, thanks!

like image 593
Giovanni Orciuolo Avatar asked Nov 07 '22 20:11

Giovanni Orciuolo


1 Answers

This is caused by the fact that angular is not stable. Have a look at the link below. I found my answer there. When the page you are trying to test is open go to the browser dev tools and type in the console getAllAngularTestabilities(). There are a few properties here that indicate whether angular is ready to be tested. hasPendingMicrotasts needs to be false. hasPendingMacroTasks needs to be false. isStable needs to be true. I put a screenshot below. In my screenshot hasPendingMacrotasks is true and it must be false. So the page I looked at was not ready to be tested.

Failed: script timeout: result was not received in 11 seconds From: Task: Protractor.waitForAngular() - Locator: By(css selector, #my-btn)

console. My page is not ready for testing

like image 56
Dani Oprean Avatar answered Nov 15 '22 06:11

Dani Oprean