首页 > 解决方案 > webdriverio中单个断言中的多个值

问题描述

是否可以将多个可能的值添加到单个期望中?就我而言,标题可能具有不同的文本值,具体取决于网站上的其他进程(下面的代码无法正常工作)。

it('card should have a one of two names', () => {
    expect(MyPage.cardName).toHaveText('Good Products' || 'Wonderfull Products');
});

同样的问题也出现在 chai 的身上deep.equal。一个断言中是否可以有多个变体?

it('should verify the card titles list', () => {
    // an array is created here
    const cardTitles = MyPage.cardTitlesText();
    chaiExpect(cardTitles).to.deep.equal(['Apples', 'Carrots', 'Tomatoes', 'Potatoes'] || ['Potatoes', 'Apples', 'Carrots', 'Tomatoes']);
});

或者也许我错过了测试的整体概念中的一些东西,而这应该首先以不同的方式处理?

标签: javascripttestinge2e-testingwebdriver-io

解决方案


现在可以在最新版本的内置expect-webdriverio中,只需传递一个字符串数组,见https://webdriver.io/docs/api/expect-webdriverio.html#tohavetext

随意向https://github.com/webdriverio/expect-webdriverio提出功能请求


推荐阅读