【问题标题】:How to check if text exists in Testcafe如何检查Testcafe中是否存在文本
【发布时间】:2019-09-28 03:53:17
【问题描述】:

我想检查我创建的页面上是否存在“64”。

const x = Selector('.FilterCockpit--header--count').withText('64');

以下测试失败。

test('x', async t => {
    await t
    .expect((x).exists).ok()
    });

HTML 代码:

<div class="FilterCockpit--header--results">
          <span class="FilterCockpit--header--count">
              64
         </span>
         Results
 </div>

我做错了什么?提前感谢您的帮助。

【问题讨论】:

  • 我在控制台中收到错误消息:AssertionError: expected false to be truthy

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


【解决方案1】:

我已经用最新的 1.1.4 版 TestCafe 执行了你的测试用例,并且通过了:

这是我的完整测试用例和基于您的代码 sn-ps 的测试文件:

import { Selector} from 'testcafe';

fixture('fixture')
    .page('file:///Temp/56074194.html');

const x = Selector('.FilterCockpit--header--count').withText('64');

test('x', async t => {

    await t
        .expect((x).exists).ok()
});

56074194.html 

<div class="FilterCockpit--header--results">
          <span class="FilterCockpit--header--count">
              64
         </span>
         Results
 </div>

也许,有些情况可能会中断测试执行。如果我需要执行任何其他步骤,请告诉我。

另见:Check if an Element Exists

【讨论】:

  • 嗨,亚历克斯。非常感谢您的回答。现在可以正常使用了。
  • 不客气。这是个好消息。很高兴得知您已经找到解决问题的方法。
猜你喜欢
  • 2019-01-19
  • 2021-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-20
  • 1970-01-01
  • 1970-01-01
  • 2015-03-05
相关资源
最近更新 更多