【问题标题】:TestCafe Runner - Is it possible to pass a constant from the createRunner file to testsTestCafe Runner - 是否可以将常量从 createRunner 文件传递​​给测试
【发布时间】:2019-02-19 20:26:24
【问题描述】:

我需要将 url 传递给在 createRunner 中执行的所有测试。我已经使用 args 从命令行执行测试。有没有办法将常量从 createRunner 传递给执行的测试?请参阅下面我正在使用的 createRunner。谢谢。

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

let testcafe = null;
let runner = null;

createTestCafe('localhost', 1337, 1338)
    .then(tc => {
        testcafe     = tc;
        runner = testcafe.createRunner();

    return runner
        // list multiple test files
        .src([
            'tests/login.js'
        ])
        .browsers(['chrome'])
        .concurrency(2)
        .reporter('slack')
        .run({
            skipJsErrors: true,
            quarantineMode: true,
            selectorTimeout: 30000,
            assertionTimeout: 10000,
            pageLoadTimeout: 15000,
            speed: 0.9
        });
})
.then(failedCount => {
    stream.end();
    console.log('Tests failed: ' + failedCount);
    testcafe.close();
});

【问题讨论】:

    标签: testing automated-tests e2e-testing testcafe test-runner


    【解决方案1】:

    一种解决方案是以编程方式注入命令行参数。在返回跑步者之前,插入这些行:

    process.argv.push('--foo=bar');
    process.argv.push('--yo');
    

    在测试文件中使用 minimist 来获取您的自定义 cli 参数。

    你的问题也是related to this one

    【讨论】:

    • 谢谢!效果很好。
    猜你喜欢
    • 2011-12-12
    • 1970-01-01
    • 2020-10-11
    • 2017-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-16
    相关资源
    最近更新 更多