testing - 如何验证带有断言的网页上不存在文本
问题描述
我是 Test Cafe Studio 的新手,我正在尝试弄清楚如何验证网页上不存在文本。如果文本存在,我希望测试失败。任何帮助,将不胜感激。
解决方案
通常,您想要断言某个元素的文本:
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');
但我认为最好避免它,而是以以下方式构建测试:
- 你检查存在,而不是缺席
- 你检查具体的东西,而不是整个页面
推荐阅读
- powershell - PowerShell:唯一的对象数组
- r - 插入符号如何拆分 trainControl 中的数据?
- c++ - c++ operator[uint] msvc x86 构建失败,构建正常 x64
- node.js - 如何编辑从 multer 返回的路径以删除特定的单词?
- typescript - 您将如何使用 lambda 简化这段代码?
- c++ - 越界访问数组,但更早返回 - UB?
- python - 合并从递归函数返回的非常大的数组
- python - 如何将函数绑定到 Qt 菜单栏中的操作?
- google-sheets-api - Bings 广告脚本 - 调用 Google 服务不起作用
- google-apps-script - Apps 脚本:收集表单输入并显示今天的总数