简体   繁体   English

为什么在使用带有 waitForAngularEnabled(true) 的量角器运行 e2e 测试时出现错误

[英]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.我正在使用量角器进行 e2e 测试我的 angular 应用程序。 For the login page I set waitForAngularEnabled(false) and afterwards I set it to waitForAngularEnabled(true).对于登录页面,我设置了waitForAngularEnabled(false),然后将其设置为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.当我用谷歌搜索它时,我发现很多帖子建议我应该关闭同步或将 waitForAngularEnabled 设置为 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.感谢这篇文章( https://christianliebel.com/2016/11/angular-2-protractor-timeout-heres-fix/ ),我发现它是由应用程序中使用的超时引起的。 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:因此,为此,您可以搜索 setInterval 和 setTimeout 并将它们替换为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在量角器e2e测试中从列表(表)中获取行? - How do I get rows from a list(table) in a protractor e2e test? 在 Azure DevOps 管道中运行时,Angular/Protractor E2E 测试失败。 本地通过 - Angular/ Protractor E2E Test fails when run in Azure DevOps Pipeline. Passes locally Angular 2 在量角器 e2e 测试中获取当前 URL - Angular 2 get current Url in protractor e2e test 如何使用 PROTRACTOR E2E 在应用程序的每个页面中重用和运行相同的测试用例? - How to reuse and run same test cases in every page of application using PROTRACTOR E2E? 使用量角器e2e测试来测量代码覆盖率Java - Measuring code coverage java using protractor e2e test 使用任务计划程序运行量角器e2e测试脚本– Windows 10 - Run Protractor e2e Test script Using Task Scheduler – Windows 10 使用量角器在测试 E2E 中上传文件 - Upload file in test E2E with Protractor 使用--spec时量角器e2e测试未运行 - Protractor e2e tests not running when using --spec 当我使用e2e运行它时,在登录我的应用程序时弹出 - pop come at login to my app when i run it using e2e 我如何解决 E/launcher - 运行 ng e2e 时,进程在 gitlab 作业上以错误代码 199 退出 - How i solve E/launcher - Process exited with error code 199 on gitlab job when run ng e2e
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM