如何在TestCafe中同时运行相同的测试以创建竞赛条件?

发布于 2025-02-05 04:01:30 字数 34 浏览 3 评论 0 原文

我正在尝试创建一个种族条件,同一测试将同时进行同时进行

I am trying to create a race condition, where the same test will run at the same time concurrently

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光病人 2025-02-12 04:01:30

如果使用 testcafe 命令来运行测试,则可以使用 - 并发选项。如果您使用使用 quoge >跑步者对象和他们带有 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();
    }
})()

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();
    }
})()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文