TestCafe——断言元素可见的正确方法

TestCafe-- Proper way to assert an element is visible

根据各种论坛讨论、TestCafe 文档以及尝试比较结果,我仍然不确定断言页面元素可见的正确(或最佳)方法。

await t.expect(Selector('#elementId').visible).ok();

await t.expect(await Selector('#elementId').visible).ok();

或者这两种方法都不正确,还有另一种更好的方法吗?这与断言元素存在相比如何?或者元素的其他属性,比如 :checked?

实际上,两种变体都是可能的。然而,最好使用第一个,因为第二个变体可能会在获取 Element State 的阶段引发错误:

Smart Assertion Query Mechanism

Or other properties of the element, such as :checked

您可以获得 Element State 并使用其 checked 选项。

await t.expect(Selector('#elementId').visible).eql(true);

这应该有帮助