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

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

问题描述

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

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

我有一个简单的html按钮,它具有要单击的id=my-btn,使用:

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:

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

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

发件人:任务:Protractor.waitForAngular()-定位器:作者(css选择器,#my-btn)

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.

所以我想让waitForAngular操作超时的原因.

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

是否可以检查 http 超时 仍然挂起?

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. 手动检查是否有定时操作.例如,我的应用程序有一个timer,它每5分钟进行一次运行状况检查.但是此timer操作一直在堆栈中,这意味着Angular从未稳定下来.
  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.

如果找到了这样的操作,则可以使用ngZone.runOutsideAngular()防止其破坏测试的稳定性.

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. 打开开发工具并运行getAllAngularTestabilities().尝试从那里获取什么信息.您可以尝试从源代码中获取更多数据.特别是这一点可能对您有用:
  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;
}

通过依次检查这三个条件中的每一个,您至少可以对导致Angular不稳定的问题有更多的了解.

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()-定位器:作者(css选择器,#my-btn)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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