TestCafe 期望文本等于以下内容之一

问题描述 投票:0回答:1

我正在编写一个测试,如果用户单击按钮,则应该只会发生 2 个场景(文本)。

例如

await t
    .click('button')
    .expect(Selector('div#result').textContent)
    .eql('My text A')
    // or 'My text B' ??

如何在 TestCafe 中测试它?

javascript testcafe
1个回答
0
投票

首先

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.');
});
© www.soinside.com 2019 - 2024. All rights reserved.