【发布时间】:2019-07-14 07:19:42
【问题描述】:
我正在使用 TestCafe 0.23.3。我正在尝试验证一个元素是启用还是禁用。这是禁用时元素的 HTML 节点:
<button class="MuiButtonBase-root-415 MuiButtonBase-disabled-416 MuiButton-root-3719 MuiButton-text-3721 MuiButton-textPrimary-3722 MuiButton-flat-3724 MuiButton-flatPrimary-3725 MuiButton-disabled-3739" tabindex="-1" type="button" disabled=""><span class="MuiButton-label-3720">Add Person</span></button>
这是启用时元素的 HTML 节点:
<button class="MuiButtonBase-root-415 MuiButton-root-7365 MuiButton-text-7367 MuiButton-textPrimary-7368 MuiButton-flat-7370 MuiButton-flatPrimary-7371" tabindex="0" type="button"><span class="MuiButton-label-7366">Add Person</span><span class="MuiTouchRipple-root-778"></span></button>
这是我用来验证元素的 TestCafe 代码:
.expect(Selector('button').withText('Add Person').hasAttribute('disabled'))
.ok();
上面的 TestCafe 代码通过了元素的启用/禁用状态,这是不正确的,因为预期的结果是检查元素是否被禁用。我不确定这里有什么问题。
【问题讨论】:
-
页面上还有其他禁用的按钮吗?如果我对文档的理解正确,则选择器将同时匹配“按钮”和“带有添加人员的按钮”,然后确定这些匹配项中是否有任何匹配项具有 disabled 属性。请参阅第一个 withText 示例后的注释:devexpress.github.io/testcafe/documentation/test-api/… 此外,此 github 问题:github.com/DevExpress/testcafe/issues/1071
-
我从
withText的文档中了解到,它会查找包含文本的元素(此处为Add Person)。它也可以传递文本Add Person People,但它不会仅查找与button匹配的元素。我也尝试过withExactText,但两种情况下的测试都再次通过了。我仔细检查了页面中没有具有相同文本Add Person的元素。
标签: testing automated-tests e2e-testing testcafe web-testing