TestCafe:await t.expect(Selector().exists).ok() 偶尔抛出 TypeError

发布于 2025-01-11 09:36:01 字数 301 浏览 4 评论 0原文

是否有任何可能的原因导致 await t.expect(Selector().exists).ok() 抛出 TypeError: Cannot read property '0' of null?它偶尔发生,所以很难追踪,但我的理解是,如果选择器不存在于 DOM 树中,那么它应该等待超时,并抛出一个预期的布尔值,如果未找到错误,则为布尔值。我知道我没有提供太多内容,但我无法在面向生产的网站上重现该问题。任何帮助将不胜感激。

编辑:这是 TestCafe 的 1.18.3 版本,但我不确定它是否也会发生在其他版本中。

Is there any possible reason for await t.expect(Selector().exists).ok() to throw TypeError: Cannot read property '0' of null? It happens sporadically so it's hard to track down but my understanding is that if the Selector is not present in the DOM tree then it should wait the timeout and throw an expected boolean to be boolean if not found error. I know I'm not providing much to go on but I'm unable to reproduce the issue on a production facing website. Any help would be greatly appreciated.

Edit: This is on version 1.18.3 of TestCafe but I'm uncertain if it happens in other versions as well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

睫毛溺水了 2025-01-18 09:36:02

虽然我没有发现失败的根本原因,但将 Expect 方法包装在重试中已经完全消除了错误。如果我获得有关原始问题的任何其他信息,我将更新此主题。

While I didn't discover the root cause of the failure, wrapping the expect methods in a retry has completely eliminated the error. I'll update this topic if I get any additional information around the original issue.

深白境迁sunset 2025-01-18 09:36:01

如果没有测试代码示例,很难找到问题的原因。您能否插入 t.wait 方法每个潜在有问题的地方之前超时,例如

await t.expect(Selector().exists).ok()

然后,观察测试如何通过,看看问题是否取决于超时。

请注意以下来自 Selector Timeout 的信息

选择器超时对 Selector.exists 和 Selector.count 没有影响
特性。无论什么,这些属性都会立即评估
暂停。要对存在应用超时并对断言进行计数,请传递
断言方法(expect.ok、expect.eql 等)超时。
如果问题取决于超时,请分享一个重现问题的小测试代码片段。

如果问题与超时无关地重现,则意味着问题出在代码的另一部分。

It's hard to find the cause of the issue without a test code example. Could you please insert the t.wait method with a big timeout before each potential problematic place, e.g.

await t.expect(Selector().exists).ok() ?

Then, observe how the tests are passed to see if the issue depends on the timeout.

Please pay attention to the following information from Selector Timeout:

Selector timeouts have no effect on Selector.exists and Selector.count
properties. These properties are evaluated immediately regardless of a
timeout. To apply a timeout to exists and count assertions, pass the
timeout to the assertion method (expect.ok, expect.eql, etc.).
If the issue depends on the timeout, please share a small test code snippet where the problem is reproduced.

If the problem is reproduced independently from the timeout, this means that the issue is in another part of your code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文