【发布时间】: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