javascript - 等待和 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">×</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"));
})
我该如何解决这个问题?
解决方案
固定的。我不得不从调用测试中禁用异常。正在工作的一个禁用了异常,而另一个没有。
推荐阅读
- reactjs - 从反应组件返回值
- excel - 如何应用 Worksheets.SaveAs 功能?
- android - 如何在 Jetpack Compose 中将视图的基线与另一个视图的顶部对齐?
- javascript - mongoose mode.findOneAndUpdate 查询不起作用
- javascript - 处理的PromiseRejectionWarning:TypeError:无法读取未定义的属性“添加”(Discord Bot)
- angular - Angular如何从另一个数组填充数组
- python - 如何从模块的项目结构外部导入 python 模块而不会出现 ModuleNotFoundError?
- scala - Flink 速率限制或异步接收器
- sql - 使用 ROW_NUMBER() OVER 更新
- javascript - 在不使用剪贴板的情况下创建文本选择的克隆