【问题标题】:testcafe runner to allow command line valuestestcafe runner 允许命令行值
【发布时间】:2019-05-07 20:09:42
【问题描述】:

我有一个这样定义的测试咖啡馆跑步者

  const createTestCafe = require('testcafe');
  const glob = require('glob');

  let runner = null;
  let testcafe = null;

  const getTests = suite => {
        return new Promise(resolve => {
       glob(suite, (er, files) => resolve(files));
       });
   };

 const runTest = suite => {
    createTestCafe()
    .then(tc => {
        testcafe = tc;
        runner = testcafe.createRunner();
    })
    .then(() => {
        return getTests(suite);
    })
    .then(testFiles => {
        runner
            .src(testFiles)
            .browsers('chrome')
            .run()
            .then(failedCount => {
                console.log(failedCount);
                testcafe.close();
            });
    });
}

const suites = {
    suite1: 'src/tests/1.spec.ts',
        'src/tests/2.spec.ts, 
    suite2: 'src/tests/3.spec.ts',
 };

runTest(suites.suite1);

如何从命令行传递套件名称、浏览器名称等,即现在,套件 1 是硬编码的,但我想从命令行选择套件名称,例如

  node testCafeRunner --suite suite2 --browser firefox

我该怎么做?

另外,如果我不得不打扰.testcaferc.jsonrunner,testcafe 会同时看吗?

【问题讨论】:

    标签: configuration automated-tests e2e-testing web-testing testcafe


    【解决方案1】:

    您可以按如下方式传递 nodejs 参数:

    node testCafeRunner.js --suite=suite2 --browser=firefox
    

    在 testCafeRunner.js 中:

    var argv = require('minimist')(process.argv.slice(2));
     
    const suite = argv.suite;
    const browser = argv.browser;
    

    从命令行运行 TestCafe 时指定的设置和编程接口会覆盖配置文件 (.testcaferc.json) 中的设置。 TestCafe 打印控制台中每个被覆盖属性的信息。

    另见

    How do I pass command line arguments to a Node.js program?

    nodejs process.argv

    https://www.npmjs.com/package/minimist

    TestCafe Configuration File

    【讨论】:

      猜你喜欢
      • 2012-05-21
      • 2011-11-10
      • 1970-01-01
      • 2013-08-18
      • 1970-01-01
      • 1970-01-01
      • 2016-06-09
      • 1970-01-01
      • 2017-10-23
      相关资源
      最近更新 更多