无法对在赛普拉斯中找到或未找到的元素执行正确的流程

Cannot perform right flow for element found or not found in Cypress

提问人:automation-ninja 提问时间:11/13/2023 更新时间:11/13/2023 访问量:23

问:

我在使用 Cypress 自定义命令时遇到了问题。该命令旨在根据某些元素的结果检查某些元素的可见性。下面是相关的代码片段:

Cypress.Commands.add('checkEstablishments', () => {
  accessManagement.getEstablishmentResult().then(($result) => {
    if ($result.length >= 1) {
      accessManagement.getEstablishments()
        .should('be.visible', { timeout: 15000 });
    } else {
      accessManagement.getEstablishmentNotFoundMsg()
        .should('exist')
        .should('be.visible')
        .and('contain.text', 'No establishment found');
    }
  });
});

运行此命令时,我在 Cypress 控制台中遇到以下错误:

if ($result.length >= 1) {
  accessManagement.getEstablishments()
    .should('be.visible');
              ^
} else {
  accessManagement.getEstablishmentNotFoundMsg()
  .should('exist')

在 accessManagement.getEstablishments() 调用后使用 .should('be.visible') 似乎存在问题。我不确定为什么会这样。有人可以帮我理解和解决这个问题吗?

JavaScript 自动化 自动化测试 Cypress UI-自动化

评论

0赞 Orla 11/14/2023
问题中缺少两件事 - 里面有什么,错误是什么?accessManagement.getEstablishments()
0赞 automation-ninja 11/14/2023
@Orla accessManagement.getEstablishments() 中有一些选择器: // getEstablishments(){ // 返回 cy.get('.MuiButtonBase-root.MuiButton-root.MuiButton-text.MuiButton-textPrimary.MuiButton-sizeMedium.MuiButton-textSizeMedium.MuiButton-root.MuiButton-text.MuiButton-textPrimary.MuiButton-sizeMedium.MuiButton-textSizeMedium.css-w8tly3-MuiButtonBase-root-MuiButton-root') // } 我正在尝试首先搜索此元素,如果没有找到,那么我应该会看到accessManagement.getEstablishmentNotFoundMsg()元素。它只寻找 getEstablishments 元素。

答: 暂无答案