简体   繁体   中英

How can I run same test concurrently in testcafe to create a race condition?

我正在尝试创建一个竞争条件,其中相同的测试将同时运行

If you use the testcafe command to run the test, you can use the --concurrency option . If you use runner , you can set concurrency using the eponymous method or just create several runner objects and run them with Promise.race :

const createTestCafe = require('testcafe');

async function runTest(testcafe, src) {
    const runner = testcafe.createRunner();

    const failed = await runner
        .src(src)
        .browsers('chrome')
        .run();

    console.log('Tests failed: ' + failed);
}

(async function () {
    const testcafe = await createTestCafe('localhost', 1337, 1338);

    try {
        await Promise.race([
            runTest(testcafe, './test1.js'),
            runTest(testcafe, './test2.js'),
            runTest(testcafe, './test3.js'),
        ])
    }
    finally {
        await testcafe.close();
    }
})()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM