在 watir 中使用“@current_page”验证 webelement

Verify webelement using "@current_page" in watir

Step1 和 Step2 带我回到 "LandingPage"。我想使用 @current_page 验证元素。 这是在 "LandingPage.rb".

中定义的元素

我已经试过了,但没有成功。缺少什么?

Step1
Step2

1. fail if not @current_page.(on(LandingPage.cart_box.present?))
2. fail if not @current_page.(on(LandingPage.cart_box)).present?
3. fail if not @current_page.(on(LandingPage.cart_box_element)).present?

假设@current_page设置在Step1Step2中,它将是LandingPage的一个实例。您不应该调用 on 方法。

根据您的目标,您可以执行以下任一操作:

@current_page.cart_box?

@current_page.cart_box_element.visible?

请注意,如果您希望检查无法通过测试,则需要在测试框架的断言库中使用结果。