Cypress.io 中的 OR 运算符

Orl*_*hev 7 node.js cypress

如果页面结果是“未找到匹配记录”或“没有可用数据”,我无法建立测试成功的条件。Cypress 中有“OR”运算符吗?(文档中没有)

我尝试使用nodejs来执行逻辑,但是cypress在第一个条件下抛出错误。

        if (cy.get('.v-table__overflow > table > tbody > tr > td').contains('No matching records found') || cy.get('.v-table__overflow > table > tbody > tr > td').contains('No data available')) {
          cy.log('Record does not exist as Expected!');
        } else {
          cy.pause();
        }
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Lah*_*ima 7

你可以用satisfy这个

cy.get('.v-table__overflow > table > tbody > tr > td')
    .should('satisfy', (elements) => {
        const text = elements[0].innerText;
        return text === 'No matching records found' || text === 'No data available';
    });
Run Code Online (Sandbox Code Playgroud)


Dan*_*nny 3

您的赛普拉斯代码完全不正确。我建议您检查断言在 Cypress 中的工作原理

更新:您可以通过执行以下操作来实现:

cy.get('.v-table__overflow > table > tbody > tr > td').should('have.not.text', 'No matching records found').and('have.not.text', 'No data available');
Run Code Online (Sandbox Code Playgroud)

或者

cy.get('.v-table__overflow > table > tbody > tr > td').invoke('text').then((text) => {
  expect(text).not.equal('No matching records found')
  expect(text).not.equal('No data available')

})
Run Code Online (Sandbox Code Playgroud)

另外,我发现您正在检查是否未显示特定消息。相反,请考虑检查是否显示了某些元素。这样测试会更清晰。