柏树测试正在计时

发布于 2025-02-10 01:58:12 字数 495 浏览 1 评论 0原文

我需要验证页面上搜索的元素之一。

如果其中一个出现,则期望陈述应评估为true。

我已经按下F12,并验证了“下载ReferencesRow”以及其他元素之一。但是,柏树的时间就会出现。

我的代码看起来还可以吗?

var numberOfElements = 0;


cy.get('downloadReferencesRow').then((body) =>{
    if (body.find('createApplicationReferencesPresent').length > 0) {
        numberOfElements +=1;
    }
    if (body.find('createApplicationNoReferencesPresent').length > 0) {
        numberOfElements +=1;
    }
});

expect(numberOfElements).eq(1);

I need to validate that one of the elements I am searching for appears on the page.

if one of them appears the expect statement should evaluate to true.

I have pressed f12 and validated that the 'downloadReferencesRow' along with one of the other elements is appearing. but cypress it timing out.

Does my code look ok?

var numberOfElements = 0;


cy.get('downloadReferencesRow').then((body) =>{
    if (body.find('createApplicationReferencesPresent').length > 0) {
        numberOfElements +=1;
    }
    if (body.find('createApplicationNoReferencesPresent').length > 0) {
        numberOfElements +=1;
    }
});

expect(numberOfElements).eq(1);

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

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

发布评论

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

评论(1

命比纸薄 2025-02-17 01:58:12

该代码具有混合同步和异步命令,这是有问题的。

您可以使用jQuery多个选择器(例如所有有条件测试)更轻松地进行操作

cy.get('createApplicationReferencesPresent,createApplicationNoReferencesPresent')
  .then($els => {
    const numberOfElements = $els.length  // 1 or 2 - fails if neither present
  })

,仅当页面稳定时才有效。

The code has mixed synchronous and asynchronous commands, which is problematic.

You can more easily do it with jQuery multiple selectors

cy.get('createApplicationReferencesPresent,createApplicationNoReferencesPresent')
  .then($els => {
    const numberOfElements = $els.length  // 1 or 2 - fails if neither present
  })

Like all conditional testing, it only works if the page is stable.

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