rubywatirverifycurrent-page

Verify webelement using "@current_page" in watir


Step1 and Step2 take me back on "LandingPage". I want to verify the element using @current_page. This is element is defined in "LandingPage.rb".

I have tried this, but no luck. Whats missing?

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?

Solution

  • Assuming that @current_page is set in Step1 or Step2, it will be an instance of LandingPage. You should not be calling the on method.

    Depending on your goal, you can do either of the following:

    @current_page.cart_box?
    

    Or

    @current_page.cart_box_element.visible?
    

    Note that if you want the check to fail the test, you will need to use the result in your test framework's assertion library.