【问题标题】:How to use ".contains" assertion to match one of the values如何使用“.contains”断言来匹配其中一个值
【发布时间】:2019-12-04 10:10:06
【问题描述】:

根据我的应用程序,单击其中一个链接可以打开两个 URL 中的一个 URL。

例如:点击 Link - X,它可以打开以下 URL 之一: http://example.com/value1http://example.com/value2

我必须为此写一个 .contains 断言,看起来像这样:

expect(currentUrl).contains(value1 or value2)

根据 TestCafe 文档, contains 不支持正则表达式,我不想使用 Match,因为我必须在那里传递不完整的 URL。

请告诉我如何做到这一点。 谢谢。

【问题讨论】:

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


    【解决方案1】:

    检查以下“当前位置”示例测试:

    import { ClientFunction } from 'testcafe';
    
    fixture `Fixture`
        .page `https://google.com`;
    
    test('Check location', async t => {
        // Some actions and assertions...
        await t
            .navigateTo(/*...*/)
            .click(/*...*/);
    
        // Then check our location
        const getLocation = ClientFunction(() => document.location.href);
        const location    = await getLocation();
    
        await t
            .expect(location.includes('microsoft') || location.includes('google')).ok();
    });
    

    【讨论】:

      【解决方案2】:

      我已经使用下面的匹配断言解决了它,但如果这也可以通过包含断言以某种方式完成,那仍然会很好。

      expect(currentUrl).match(/value1|value2$/)
      

      【讨论】:

        猜你喜欢
        • 2021-03-16
        • 2021-04-13
        • 2018-05-28
        • 2016-01-05
        • 1970-01-01
        • 1970-01-01
        • 2020-02-24
        • 2017-09-09
        • 2020-03-16
        相关资源
        最近更新 更多