小编Bas*_*din的帖子

如何从 cypress 中的单个元素查询多个内容

我正在尝试测试 cypress 中弹出窗口/模式的内容。我的第一直觉是重复命令来获取模态元素,如下所示:

it('filter modal/popup', () => {
    cy.get('.some-button').click();
    cy.get('.some-modal').contains('abc').should('be.visible');
    cy.get('.some-modal').contains('def').should('be.visible');
    cy.getByCyTag('.some-modal').contains('xyz').should('be.visible');
});
Run Code Online (Sandbox Code Playgroud)

然而,“作为一名程序员”,查询“folder-tree-filter-modal”三次甚至更多次让我有点不舒服。由于您无法将 cypress 对象存储在变量中,因为它们会产生结果,因此我尝试使用 cypress 的 then() 基于 Promise 的语法,但这看起来也并没有好多少:

it('filter modal/popup', () => {
    cy.get('.some-button').click();
    cy.get('.some-modal').then((modal) => {
        cy.wrap(modal).should('be.visible');
        cy.wrap(modal).contains('abc').should('be.visible');
        cy.wrap(modal).contains('def').should('be.visible');
        cy.wrap(modal).contains('xyz').should('be.visible');
    });
});
Run Code Online (Sandbox Code Playgroud)

是我想太多还是有更好的方法?

cypress

1
推荐指数
1
解决办法
5240
查看次数

标签 统计

cypress ×1