失败:脚本超时:11 秒内未收到结果来自:任务:Protractor.waitForAngular() - 定位器:By(css 选择器,#my-btn) [英] Failed: script timeout: result was not received in 11 seconds From: Task: Protractor.waitForAngular() - Locator: By(css selector, #my-btn)

查看:16
本文介绍了失败:脚本超时:11 秒内未收到结果来自:任务:Protractor.waitForAngular() - 定位器:By(css 选择器,#my-btn)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Angular 应用程序编写一些 e2e 测试www.protractortest.org" rel="noreferrer">量角器.

我有一个简单的 html 按钮,其中包含我想点击的 id=my-btn,使用:

$('#my-btn').click();

很遗憾,我收到以下错误:

<块引用>

失败:脚本超时:11 秒内未收到结果

来自:任务:Protractor.waitForAngular() - 定位器:By(css selector, #my-btn)

(会话信息:chrome=73.0.3683.75)(驱动程序信息:chromedriver=2.46.628411 (3324f4c8be9ff2f70a05a30ebc72ffb013e1a71e),平台=Mac OS X 10.14.3 x86_64)

如果在点击之前我设置:

browser.waitForAngularEnabled(false);

那么我没有收到任何错误.问题是这样做意味着:

<块引用>

 * 如果设置为 false,Protractor 将不会等待 Angular $http 和 $timeout* 在与浏览器交互之前要完成的任务.这可能导致* 不稳定的测试,但应该在例如你的应用程序连续使用时使用* 使用 $timeout 轮询 API.

所以我想知道是什么导致 waitForAngular 操作超时.

有没有办法检查 httptimeout 仍然挂起?

我想调试我的应用程序以了解发生了什么.

解决方案

我遇到了一些麻烦.您可以尝试一些方法.

  1. 手动检查是否有任何定时操作.例如,我的应用程序有一个 timer 每 5 分钟进行一次健康检查.但是这个 timer 操作一直在堆栈上意味着 Angular 永远不会稳定下来.

如果你确实发现了这样的操作,你可以使用 ngZone.runOutsideAngular() 来防止它破坏你的测试.

构造函数(私有 ngZone:NgZone) {}ngOnInit() {this.ngZone.runOutsideAngular(() => {this.appStatusInterval = 间隔(this.appStatusUpdateIntervalTime)//你的其余代码在这里});});}

  1. 打开开发工具并运行 getAllAngularTestabilities().尝试从那里获得什么信息.您可以尝试从 源代码获取额外数据.这一点可能对您特别有用:

isStable(): boolean {返回 this._isZoneStable &&this._pendingCount === 0 &&!this._ngZone.hasPendingMacrotasks;}

通过依次检查这三个条件中的每一个,您至少可以更多地了解是什么破坏了 Angular 的稳定性.

I'm trying to write some e2e test for my Angular application using Protractor.

I have a simple html button having id=my-btn which I want to click, using:

$('#my-btn').click();

Unfortunately I'm getting the following errors:

Failed: script timeout: result was not received in 11 seconds

From: Task: Protractor.waitForAngular() - Locator: By(css selector, #my-btn)

(Session info: chrome=73.0.3683.75)
(Driver info: chromedriver=2.46.628411 (3324f4c8be9ff2f70a05a30ebc72ffb013e1a71e),platform=Mac OS X 10.14.3 x86_64)

If before the click I set:

browser.waitForAngularEnabled(false);

then I don't get any errors. The problem is that doing that means:

 * If set to false, Protractor will not wait for Angular $http and $timeout
 * tasks to complete before interacting with the browser. This can cause
 * flaky tests, but should be used if, for instance, your app continuously
 * polls an API with $timeout.

So I would like what is causing the waitForAngular operation to timeout.

Is there a way to check what http or timeout are still hanging?

I want to debug my application to understand what's going on.

解决方案

I had some trouble with this. There are a few things you can try.

  1. Manually check to see if you have any timed operations. My app, for example, had a timer that does a health check every 5 minutes. But this timer operation being on the stack constantly meant that Angular never stabilized.

If you do find such an operation, you can use ngZone.runOutsideAngular() to keep it from destabilizing your tests.

constructor(
    private ngZone: NgZone
  ) {}

ngOnInit() {
  this.ngZone.runOutsideAngular(() => {
    this.appStatusInterval = interval(this.appStatusUpdateIntervalTime)
       // rest of your code here
    });
  });
}

  1. Open the dev tools and run getAllAngularTestabilities(). Try to get what information you can from there. You can try to get extra data from the source code. This bit in particular might be useful to you:

isStable(): boolean {
    return this._isZoneStable && this._pendingCount === 0 && !this._ngZone.hasPendingMacrotasks;
}

You can at least get more of an idea on what's destabilizing Angular by checking each of these three conditions in turn.

这篇关于失败:脚本超时:11 秒内未收到结果来自:任务:Protractor.waitForAngular() - 定位器:By(css 选择器,#my-btn)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆