问题
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();
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?
回答1:
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:
Smart Assertion Query Mechanism
Or other properties of the element, such as :checked
You can obtain the Element State and use its checked option.
来源:https://stackoverflow.com/questions/51486699/testcafe-proper-way-to-assert-an-element-is-visible