【发布时间】:2021-01-06 16:08:50
【问题描述】:
我正在使用 cypress 框架来测试节点应用程序。我想检查变量是否设置为“SUCCESS”。最初它被设置为“FAILURE”,但从 cypress exec 中它被设置为“SUCCESS”。但是当我调用该函数时,它仍然是“失败”。有人可以帮我理解我在哪里做错了。
cypress\support\returnStatus.js
module.exports = function() {
this.returnStatus = "FAILURE";
this.SuccessMsg = function() {
cy.exec('echo hello', { log: true, failOnNonZeroExit: false }).then((output) => {
this.returnValue = "SUCCESS";
});
}
}
cypress\integration\checkReturnValue.spec.js
let Status = require('../support/returnStatus');
let helper = new Status();
describe("Check return value", function(){
it("should check latest value", function(){
let reply = helper.SuccessMsg();
console.log(reply);//still it prints /*FAILURE*/
})
});
【问题讨论】:
-
这无法从您提供的代码中重现。
this.SuccessMsg = ...没有在导出上公开函数,所以helper.SuccessMsg()是未定义的。请发布说明问题的代码。 -
嗨@AloysiusParker,感谢您指出,我已经修改了代码
标签: javascript node.js cypress