【问题标题】:How to verify text does not exist on a web page with assertions如何验证带有断言的网页上不存在文本
【发布时间】:2021-02-25 15:50:36
【问题描述】:

我是 Test Cafe Studio 的新手,我正在尝试弄清楚如何验证网页上不存在文本。如果文本存在,我希望测试失败。任何帮助将不胜感激。

【问题讨论】:

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


    【解决方案1】:

    通常,您想要断言某个元素的文本:

    const elText = await Selector('#my-element').textContent;
    await t
        .expect(elText).notContains('some text');
    

    如果你想检查整个页面,你可以这样做:

    const elText = await Selector('html').textContent;
    await t
        .expect(elText).notContains('some text');
    

    但我认为最好避免它,而是以如下方式构建测试:

    • 检查是否存在,而不是缺席
    • 你检查的是具体的东西,而不是整个页面

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-09
      • 1970-01-01
      • 1970-01-01
      • 2012-12-15
      • 2013-11-24
      相关资源
      最近更新 更多