我正在尝试使用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.exce”
示例 在你的 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);
});
},
});
}
关于python - 后台进程的 cy.exec 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71727463/