失败:脚本超时:11秒内没有收到结果来自:任务:Protractor.waitForAngular() - 定位器:By(css选择器,#my-btn)

问题描述 投票:0回答:1

我正在尝试使用Angular为我的Protractor应用程序编写一些e2e测试。

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

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

不幸的是我收到以下错误:

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

来自:任务:Protractor.waitForAngular() - 定位器:By(css选择器,#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)

如果在我设置的点击之前:

browser.waitForAngularEnabled(false);

然后我没有得到任何错误。问题是这样做意味着:

 * 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操作超时。

有没有办法检查仍然悬挂的http或超时?

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

angular typescript protractor e2e-testing angular-e2e
1个回答
4
投票

我遇到了一些麻烦。你可以尝试一些事情。

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

如果你确实找到了这样的操作,你可以使用ngZone.runOutsideAngular()来防止你的测试不稳定。

constructor(
    private ngZone: NgZone
  ) {}

ngOnInit() {
  this.ngZone.runOutsideAngular(() => {
    this.appStatusInterval = interval(this.appStatusUpdateIntervalTime)
       // rest of your code here
    });
  });
}
  1. 打开开发工具并运行getAllAngularTestabilities()。尝试从那里获得您可以获得的信息。您可以尝试从the source code获取额外数据。特别是这一点可能对您有用:
isStable(): boolean {
    return this._isZoneStable && this._pendingCount === 0 && !this._ngZone.hasPendingMacrotasks;
}

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

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.