testing - 检查 img src 在 TestCafe 中的路径是否正确

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

我使用 TestCafe 执行测试,需要检查 img 是否具有正确的路径。有两个 img 元素:

案例一:

<div class="x-grid3-cell-inner x-grid3-col-2" unselectable="on" id="dynamicID1">
     <img src="images/icons/bullet_wh.png">
     <img src="images/icons/bullet_re.png" id="dynamicID2">
</div>

本例结果:之前有错误。

案例二:

<div class="x-grid3-cell-inner x-grid3-col-2" unselectable="on" id="dynamicID3">
     <img src="images/icons/bullet_gr.png">
     <img src="images/icons/bullet_wh.png" id="dynamicID4">
</div>

本案例的结果:bullet_gr.png 在网站上。一切正常!

在我的测试中,我使用 .expect(Selector('img[src="images/icons/bullet_gr.png"]')) 检查 bullet_gr.png 在我的网站上可见。不幸的是,每次访问时 ID 都不同(它们在用户登录时呈现,并且每次访问都是唯一的)。所以我不能使用 .expect(Selector('#dynamicID4'))

一旦我在测试中使用 .expect(Selector('img[src="images/icons/bullet_gr.png"]')) 行,一旦用户登录测试,我得到测试成功的输出。

检查站点上是否链接了 bullet_gr.png 的解决方案是什么?

最佳答案

要检查元素是否在页面上,请使用 exists属性:

await t.expect(Selector('img[src="images/icons/bullet_gr.png"]')).ok()

const img = Selector('img').withAttribute('src', 'images/icons/bullet_gr.png');

await t.expect(img.exists).ok();

关于testing - 检查 img src 在 TestCafe 中的路径是否正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47864494/

相关文章:

performance - Jmeter如何登录大量用户?

angularjs - 手动安装 Selenium Server 以使用古巴的 Protractor (AngularJS)

javascript - Cypress:子命令主题似乎不是一个元素

c++ - 如何嵌入实时单元测试函数的主体作为 Doxygen 的示例用法?

java - 在测试应用程序或网站时,本地化和国际化测试是否重要?

iframe - 在 TestCafe 中使用嵌套 iframe 内的 Expect

typescript - TestCafe - 检查超链接是否有效 - 重定向到外部电子邮件提供商

testing - Grails 集成测试过滤器

ruby-on-rails - 如果我的 Rails 测试没有通过,我该怎么办?

testing - 如何在不要求参数函数可变的情况下测试元函数?