如何检查 Testcafe 中是否存在文本

Jak*_*Sip 3 testing automated-tests web-testing e2e-testing testcafe

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

const x = Selector('.FilterCockpit--header--count').withText('64');
Run Code Online (Sandbox Code Playgroud)

以下测试失败。

test('x', async t => {
    await t
    .expect((x).exists).ok()
    });
Run Code Online (Sandbox Code Playgroud)

HTML 代码:

<div class="FilterCockpit--header--results">
          <span class="FilterCockpit--header--count">
              64
         </span>
         Results
 </div>
Run Code Online (Sandbox Code Playgroud)

我做错了什么?预先感谢您的帮助。

Ale*_*kin 5

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

\n\n

在此输入图像描述

\n\n

这是我的完整测试用例和基于您的代码片段的测试文件:

\n\n
import { Selector} from \'testcafe\';\n\nfixture(\'fixture\')\n    .page(\'file:///Temp/56074194.html\');\n\nconst x = Selector(\'.FilterCockpit--header--count\').withText(\'64\');\n\ntest(\'x\', async t => {\n\n    await t\n        .expect((x).exists).ok()\n});\n
Run Code Online (Sandbox Code Playgroud)\n\n

56074194.html\xc2\xa0

\n\n
<div class="FilterCockpit--header--results">\n          <span class="FilterCockpit--header--count">\n              64\n         </span>\n         Results\n </div>\n
Run Code Online (Sandbox Code Playgroud)\n\n

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

\n\n

另请参阅:检查元素是否存在

\n