从 TestCafe 脚本转义到 shell
Escape to shell from TestCafe script
我正在编写一个 TestCafe 脚本,我在其中捕获了一个端点 URL,它需要作为 shell/bash 命令的输入。
const inputText = await Selector('textarea[name="url-input"]').value;
console.info(`This is my URL of interest ${inputText}`)
然后我想用inputText
执行一个bash命令,说(为了简单)
echo inputText
这如何从我的 testcafe 脚本中完成?我找不到与此相关的 post 文档。
我确实在 Javascript 上找到了一个使用 process.createChildProcess('command');
的相关 post,但我仍在努力使这个解决方案起作用。请参阅文档 here
// on declarations
const { exec } = require('child_process');
// inside the test
exec('echo "The \$HOME variable is $HOME"');
我让它可以与来自 this 1 and this 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);
}
});
我正在编写一个 TestCafe 脚本,我在其中捕获了一个端点 URL,它需要作为 shell/bash 命令的输入。
const inputText = await Selector('textarea[name="url-input"]').value;
console.info(`This is my URL of interest ${inputText}`)
然后我想用inputText
执行一个bash命令,说(为了简单)
echo inputText
这如何从我的 testcafe 脚本中完成?我找不到与此相关的 post 文档。
我确实在 Javascript 上找到了一个使用 process.createChildProcess('command');
的相关 post,但我仍在努力使这个解决方案起作用。请参阅文档 here
// on declarations
const { exec } = require('child_process');
// inside the test
exec('echo "The \$HOME variable is $HOME"');
我让它可以与来自 this 1 and this 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);
}
});