使用HTML报告按顺序运行Testcafe测试

问题描述

这不是问题。我只想与HTML报告共享按顺序运行testcafe测试的解决方案。 对我来说,在不同的浏览器上并行运行测试不是一个解决方案。我必须等待对一个环境的测试完成,然后才能在下一个环境中运行。 我花了一些时间才弄清楚,但是对我有用。 如果有人有更好的解决方案,请通知我。

只需将此代码(具有您的特定自定义设置)添加到运行文件中即可。即runner.js 并使用node runner.js命令运行它。

解决方案:

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

const browsers = [
    'chrome','firefox'
];

let stream = null;
const runTest = async browser => {
    console.log('----------------- starting tests on ' + browser);
    await createtestcafe('localhost',1337,1338)
        .then(tc => {
            testcafe = tc;
            const runner = testcafe.createRunner();

            return runner
                .src([
                    "./smokeTests/someTests.js"
                ])
                .browsers(browser)
                .reporter('html',stream)
                .run();
        })
        .then(async FailedCount => {
            console.log('Tests Failed: ' + FailedCount);
            await testcafe.close();
            return;
        });
}

const runAllbrowsers = async () => {

    for (const browser of browsers) {
        stream = fs.createWriteStream('./testResults' +'/report_' + browser + '.html'); 

        await runTest(browser);
        await testcafe.close();
    }
}

runAllbrowsers();

我使用了https://github.com/DevExpress/testcafe/issues/2495的原始想法。 我要感谢nabrahamson的初衷!

解决方法

感谢您与所有人共享此解决方案。

您可能还希望将示例贡献给testcafe-examples回购。