当断言找到一个元素时是否需要使用 .exists ?

When asserting that an element is found is using .exists necessary?

看来,

t.expect(Selector("[data-testid='foo']")).ok();

并且,

t.expect(Selector("[data-testid='foo']").exists).ok();

结果相同所以.exists有必要吗?

Selector("[data-testid='foo']") returns 一个承诺。 无论页面上是否有元素,t.expect(Selector("[data-testid='foo']")).ok(); 断言总是会通过。发生这种情况是因为 Promise 实例将被转换为 true

t.expect(Selector("[data-testid='foo']").exists).ok(); 是正确的断言。它使用 Smart assertion query mechanism

检查页面上的元素