【问题标题】:How it is possible to replace Cypress error message with a custom message如何用自定义消息替换赛普拉斯错误消息
【发布时间】:2021-09-30 22:39:28
【问题描述】:

我正在尝试解析一个大文件并使用 cypress 断言文件中不包含字符串。我想替换断言消息以保持我的日志干净。我试过这个: 我将内容包装如下:

cy.task('parsePdf', filePath)
  .its('text')
  .then(($txt) => {
    cy.wrap($txt).as('content');
  });

然后我尝试使用 Chai expect 断言这一点,并以两种结果相同的方式插入自定义消息:

第一:

cy.get('@content').should(($txt) => {
  expect($txt).to.not.include(
    'text that should not be in the content',
    'Custom error message'
  );
});

第二:

cy.get('@content').should(($txt) => {
  expect($txt, 'Custom error message').to.not.include(
    'text that should not be in the content');
});

结果:

Custom error message 预期 Full report content 不包括 text that should not be in the content

我寻找的只是在失败中记录Custom error message

预期:

Custom error message

【问题讨论】:

    标签: cypress chai


    【解决方案1】:

    大概是这样的:

    cy.get('@content').should(($txt) => {
      const flag = $txt.includes('text that should be in the content');
      assert.isTrue(flag, 'Custom message');
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-11
      • 2013-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-21
      相关资源
      最近更新 更多