Skip to content
Titus edited this page Jan 27, 2018 · 2 revisions

Watir Drops will verify you are on the correct page if you add a keyword required:true into #self.page_url, #self.element or by creating a #self.page_title method like the following:

    class PageRequired < WatirDrops::PageObject
      page_url (required: true) { 'https://www.google.ca/?gws_rd=ssl' }
      page_title { 'Google' }
      element(:search, required : true) { browser.text_field(id: 'lst-ib') }
    end

PageRequired.visit will automatically verify the correctness of url, title and presence of required elements for the target page. If verification fails, an exception: Selenium::WebDriver::Error::WebDriverError will be raised.

This happens since visit automatically calls an instance method #on_page? to verify the correctness of page if any component is ‘required’ to be verified.

We can also call PageRequired.new.on_page? directly, which will simply return the verification result true or false.

However, if a page is defined, but nothing is required to be verified like following:

    class NoneRequired < WatirDrops::PageObject
      page_url { 'http://bit.ly/watir-webdriver-demo' }
      element(:search) { browser.text_field(id: 'lst-ib') }
    end

NoneRequired.visit will not verify anything and NoneRequired.new.on_page? will throw an exception since user is asking for verification but nothing is verifiable!

Clone this wiki locally