【问题标题】:Escape to shell from TestCafe script从 TestCafe 脚本逃逸到 shell
【发布时间】:2019-06-17 15:25:20
【问题描述】:

我正在编写一个 TestCafe 脚本,在该脚本中我捕获了一个端点 URL,该 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 脚本来实现这一点?我找不到有关此文档的相关帖子。

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

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

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

【问题讨论】:

    标签: javascript bash automated-tests e2e-testing testcafe


    【解决方案1】:

    我得到了它与 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);
          }
        });
    

    【讨论】:

      猜你喜欢
      • 2015-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多