据我了解,此错误发生在ResizeObserver
无法在单个动画帧内提供所有观察结果。该书的作者ResizeObserver
规范确保可以安全地忽略它:超出 ResizeObserver 循环限制 https://stackoverflow.com/questions/49384120/resizeobserver-loop-limit-exceeded#comment86691361_49384120
Chrome 和 Firefox 默认情况下不显示它。只有当你设置显式的时候你才能捕获它onerror
处理程序:
window.onerror = e => console.log(e);
您可以看到此错误在没有 TestCafe 的 Google 登录页面上重现。我添加了一个onerror
处理程序到页面并得到ResizeObserver loop completed with undelivered notifications.
在火狐和ResizeObserver loop limit exceeded
在 Chrome 中。
作为解决方法,您可以指定--skip-js-errors
启动 TestCafe 时标记。我承认这不是最好的方法,因为您将抑制测试页面上的所有 Javascript 错误。
更可靠的方法是在测试中显式添加全局窗口错误处理程序客户端脚本 https://devexpress.github.io/testcafe/documentation/using-testcafe/common-concepts/inject-scripts-into-tested-pages.html:
import { Selector, t } from 'testcafe';
// Constants
const gmailEmailInput = Selector("#identifierId");
const gmailNextButton = Selector(".CwaK9");
const gmailPasswordInput = Selector("input[type='password']");
const explicitErrorHandler = () => {
window.addEventListener('error', e => {
if(e.message === 'ResizeObserver loop completed with undelivered notifications.' ||
e.message === 'ResizeObserver loop limit exceeded') {
e.stopImmediatePropagation();
}
})
}
fixture("Gmail login test")
.clientScripts({ content: `(${explicitErrorHandler.toString()})()` });
test("Not trigger JS error when logging in to Gmail", async testController => {
await testController
.navigateTo("https://mail.google.com")
.typeText(gmailEmailInput, "[email protected] /cdn-cgi/l/email-protection")
.click(gmailNextButton)
.typeText(gmailPasswordInput, "password")
});
我复制粘贴了解决方法here https://github.com/DevExpress/testcafe/issues/4857#issuecomment-598775956.