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

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

我想检查我创建的页面上是否存在“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>

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

最佳答案

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

enter image description here

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

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

关于testing - 如何检查Testcafe中是否存在文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56074194/

相关文章:

asp.net - 如何以编程方式登录到使用表单例份验证的 ASP.NET 网站?

internet-explorer - 如何在 Selenium 中使用 IEDriverServer 避免 "Protected Mode"问题?

javascript - 页面模型导入

perl - 仅当安装了所需的模块时,如何才能在我的 Perl 模块的测试套件中运行测试?

python - 在函数中将闭包传递给 FunctionType

java - 编写一个类,以便它可以扩展或传递 block JAVA

java - 测试 Java 代码

c# - [Test](可选 [Values])与 [TestCase](可选 ExpectedResult)之间有什么区别?

testing - 在 TestCafe 中测试期间在浏览器控制台中运行命令

javascript - 为什么toBe()在测试中不起作用 - Protractor e2e