简体   繁体   中英

Why I get an error when I run an e2e test using protractor with waitForAngularEnabled(true)

I'm using protractor for e2e testing my angular app. For the login page I set waitForAngularEnabled(false) and afterwards I set it to waitForAngularEnabled(true). But my tests are failing with this error:

 Failed: script timeout
          (Session info: chrome=85.0.4183.83)
          (Driver info: chromedriver=85.0.4183.38 (9047dbc2c693f044042bbec5c91401c708c7c26a-refs/branch-heads/4183@{#779}),platform=Windows NT 10.0.18362 x86_64)
          (Session info: chrome=85.0.4183.83)
          (Driver info: chromedriver=85.0.4183.38 (9047dbc2c693f044042bbec5c91401c708c7c26a-refs/branch-heads/4183@{#779}),platform=Windows NT 10.0.18362 x86_64)
            at Object.checkLegacyResponse (....node_modules\selenium-webdriver\lib\error.js:546:15)
            at parseHttpResponse (....node_modules\selenium-webdriver\lib\http.js:509:13)
            at doSend.then.response (....node_modules\selenium-webdriver\lib\http.js:441:30)
            at process._tickCallback (internal/process/next_tick.js:68:7)
        From: Task: Protractor.waitForAngular() - Locator: By(css selector, body)

When I google for it I find a lot of posts suggesting I should set synchronization off or set waitForAngularEnabled to false. But then I loose this functionality.

Someone has an idea how to fix this?

I found out thanks to this post ( https://christianliebel.com/2016/11/angular-2-protractor-timeout-heres-fix/ ) that it was caused by timeouts which are used in the app. I replaced them with the proposed solution and now it works like a charm.

So for this to work you search for setInterval and setTimeout and replace them with:

ngZone.runOutsideAngular(() => {
    setInterval(() => {
        ngZone.run(() => {
            // async operation
        });
    }, 2500); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM