【问题标题】:Failed to run tests with more than 3 users with testcafe使用 testcafe 运行超过 3 个用户的测试失败
【发布时间】:2021-12-07 22:07:02
【问题描述】:

testcafe的github上有一个多用户场景的例子。

https://github.com/DevExpress/testcafe-example-multiuser-scenario

我正在尝试扩展它并确保它适用于 3 个用户。

https://github.com/touka-tt/testcafe-example-multiuser-scenario

  • third-user-test.js
const { Selector } = require('testcafe');

const { getScenario } = require('..');

const scenario = getScenario('An example of synchronizing multiple tests');
const stage    = scenario.initUser('Third user');

fixture`Third fixture`
    .page('http://localhost:3000');

const input = Selector('input');
const h1    = Selector('h1');

test('test', async t => {
    await stage('Check page load');

    await t.expect(input.exists).ok();

    await stage('Type a color and send it');

    await t
        .typeText(input, 'red')
        .pressKey('enter');

    await stage('Check result');

    await t.expect(h1.innerText).eql('Not ok!');

    await stage('End');
});
  • scenario-gist.js
const { Scenario } = require('..');

module.exports = async () => {
    const scenario = new Scenario('An example of synchronizing multiple tests');

    const [user1, user2, user3] = await Promise.all([
        scenario.createUser('First user', 'test/first-user-test.js', 'chrome'),
        scenario.createUser('Second user', 'test/second-user-test.js', 'chrome --incognito'),
        scenario.createUser('Third user', 'test/third-user-test.js', 'chrome --incognito')
    ]);

    await Promise.all([
        user1.runStage('Check page load'),
        user2.runStage('Check page load'),
        user3.runStage('Check page load')
    ]);

    await user1.runStage('Type a color and send it');
    await user1.runStage('Check result');

    await user2.runStage('Type a color and send it');
    await user2.runStage('Check result');

    await user3.runStage('Type a color and send it');
    await user3.runStage('Check result');

    user1.runStage('End');
    user2.runStage('End');
    user3.runStage('End');
};

乍一看,这个测试似乎运行良好。但是,第一次运行测试时,它成功了,但在第二次及以后的运行中,它在第一次 createUser 处停止。

请告诉我如何使用 testcafe 开发一个可以由多个用户重复的 e2e 测试。

【问题讨论】:

    标签: javascript testing automated-tests e2e-testing testcafe


    【解决方案1】:

    我找到了故障的原因。事实上,从 v1.15.3 开始,TestCafe 会重置测试文件中请求的模块的缓存。因此,getScenario 有时会尝试在已被覆盖的对象中查找脚本。

    我已在存储库中修复了此错误:https://github.com/DevExpress/testcafe-example-multiuser-scenario

    在 PR 中进行了更改:https://github.com/DevExpress/testcafe-example-multiuser-scenario/pull/3

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-02
      • 2019-08-27
      • 2020-03-04
      • 2020-01-07
      • 1970-01-01
      • 2013-05-20
      • 1970-01-01
      相关资源
      最近更新 更多