簡體   English   中英

如何在 testcafe 中同時運行相同的測試以創建競爭條件?

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

我正在嘗試創建一個競爭條件,其中相同的測試將同時運行

如果使用testcafe命令運行測試,可以使用--concurrency選項 如果您使用runner ,您可以使用同名方法設置並發,或者只創建幾個runner對象並使用Promise.race run它們:

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();
    }
})()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM