我正在编写一个测试,如果用户单击按钮,则应该只会发生 2 个场景(文本)。
例如
await t
.click('button')
.expect(Selector('div#result').textContent)
.eql('My text A')
// or 'My text B' ??
如何在 TestCafe 中测试它?
首先
await
用户单击按钮,然后将 textContent
保存在变量中,在 expect
中,您可以使用 or
运算符 ||
检查这两个条件,如果 false
它将输出ok
内的消息。
test('Button click results in one of two texts', async t => {
await t.click('button');
const textContent = await Selector('div#result').textContent;
await t.expect(textContent === 'My text A' || textContent === 'My text B')
.ok('Wrong text.');
});