gpt4 book ai didi

javascript - 从 TestCafe 脚本转义到 shell

转载 作者:行者123 更新时间:2023-11-29 09:26:57 25 4
gpt4 key购买 nike

我正在编写一个 TestCafe 脚本,我在其中捕获需要用作 shell/bash 命令输入的端点 URL。

const inputText = await Selector('textarea[name="url-input"]').value;
console.info(`This is my URL of interest ${inputText}`)

然后我想使用 inputText 来执行一个 bash 命令,比如(为了简单起见)

echo inputText

这如何从我的 testcafe 脚本中完成?我找不到与此相关的文档帖子。

我确实在 Javascript 上找到了一篇使用 process.createChildProcess('command'); 的相关文章,但我仍在努力使这个解决方案发挥作用。请参阅文档 here

// on declarations
const { exec } = require('child_process');

// inside the test
exec('echo "The \\$HOME variable is $HOME"');

最佳答案

我让它与以下内容一起使用,来自 this 1this 2 .

// on declarations
const { exec } = require('child_process');

// inside the test
const inputText = await Selector('textarea[name="url-input"]').value;
exec(inputText,
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.error('exec error: ' + error);
}
});

关于javascript - 从 TestCafe 脚本转义到 shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56634388/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com