我正在尝试使用启动服务器cy.exec
并像这样后台处理:
cy.exec('nohup python -m my_module arg_1 &', { failOnNonZeroExit: false }).then(result => {
if (result.code != 0) {
throw new Error(`Execution of "${command}" failed
Exit code: ${result.code}
Stdout:\n${result.stdout}
Stderr:\n${result.stderr}`);
}
})
但是,这会导致超时错误,就像进程在前台运行一样。我意识到启动服务器cy.exec
是一种反模式,但我有一个非常特殊的情况,我需要为每个测试启动具有不同参数的服务器。
我认为通过后台进程我可以绕过超时要求cy.exec
.
但是,如果这不是一个选项,那么这种情况的最佳实践是什么,即每个 cypress 测试启动不同的服务器?
您可以尝试使用 cypress 任务而不是“cy.excel”
例子
在你的 cypress/plugins/index.js 中
const startServer = async function (ExecuteCommandWithPath) {
exec(ExecuteCommandWithPath,
(error, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
if (error !== null) {
console.log(`exec error: ${error}`);
return false;
}
return true;
});
};
module.exports = ( on, config ) => {
on("task", {
PythonServerStatUp(ExecuteCommandWithPath) {
return new Promise((resolve, reject) => {
startServer(ExecuteCommandWithPath);
resolve(false);
});
},
});
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)