首页 > 解决方案 > 等待和 AddContext Promise 错误 Cypress

问题描述

我正在创建一个允许用户注释的自定义命令。它暂停测试的执行并打开一个对话框,让用户输入注释以及单击通过/失败按钮。它适用于我正在进行的一项测试,但对于另一项测试却失败了

Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.

The command that returned the promise was:

  > cy.wait()

The cy command you invoked inside the promise was:

  > cy.addContext()

这是自定义命令的代码。

Cypress.Commands.add('manualTest', (message) => {
  const doc = cy.state('document')
  const body = doc.body;
  Cypress.$(body).append('<div id="myModal" style="display: none; position: fixed; z-index: 1; padding-top: 100px; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgb(0,0,0); background-color: rgba(0,0,0,0.4)">'+
  '<div style="background-color: #fefefe; margin: auto;padding: 20px; border: 1px solid #888; width: 80%;">' +
    '<span class="close">&times;</span>' +
    '<h1>Try the following steps: ' + message + '</h1>' +
        '<input type="text" id="progressTxt"></input><br>'+
        '<input type="button" id="passBtn" value="Pass"></input>' +
        '<input type="button" id="failBtn" value="Fail"></input>' +
  '</div>' +
'</div>');

  var logValue = "";
  Cypress.$("#myModal").css("display", "block");
  Cypress.$("#passBtn").focus(function() {
     logValue = "PASSED TEST. LOG: " + Cypress.$("#progressTxt").val();
     cy.addContext(logValue);
  });
  Cypress.$("#failBtn").focus(function() {
    logValue = "FAILED TEST. LOG: " + Cypress.$("#progressTxt").val();
    cy.addContext(logValue);
 });
 
 cy.waitUntil(() => cy.focused().then($el => $el.val() == "Pass" || $el.val() == "Fail"));
 
})

我该如何解决这个问题?

标签: javascripthtmlnode.jscypress

解决方案


固定的。我不得不从调用测试中禁用异常。正在工作的一个禁用了异常,而另一个没有。


推荐阅读