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

问题描述:

基于各种论坛讨论,TestCafe文档,并尝试将其与结果进行比较,我仍然不确定哪种是断言页面元素可见的正确(或最佳方法).

Based on various forum discussions, the TestCafe documentation, and trying it out to compare results, I am still not certain which is the correct (or best) way to assert that a page element is visible.

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

vs

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

还是这些都不正确,还有另一种方法更可取?与断言元素存在相比,这有何不同?或元素的其他属性,例如:checked?

Or are these both incorrect and there is another way that is preferable? How does this compare to asserting that an element exists? Or other properties of the element, such as :checked?

实际上,两种变体都是可能的.不过,最好使用第一个,因为第二个变体在获取

Actually, both variants are possible. Nevertheless, it is better to use the first one because the second variant may raise errors at the stage of obtaining the Element State:

智能声明查询机制

元素的其他属性,例如:checked

Or other properties of the element, such as :checked

您可以获取元素状态,并使用其

You can obtain the Element State and use its checked option.