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

Similar to Form Validation, Watir Drops provides a convenience method #valid? to automatically ensure the values of data stored in a hash convertible object are equal to the values of the correspondingly named elements on the page.

To use this feature, ensure that on any page that requires validating data, you explicitly include the DataValidation module:

class UserModel < WatirModel
  key(:username) { 'Fred Johnson' }
  key(:password) { 'Password123' }
end

class HomePage < WatirDrops::PageObject
  include WatirDrops::DataValidation

  element(:username) { browser.div(id: 'current_user) } 
end

Because only username is common between both the model and the page, it is the only value that will be used in the validation. This happens by way of the #valid? method:

user = UserModel.new
LoginPage.submit_form(user)
HomePage.new.valid?(user).to eq true

TO DO: ADD EXAMPLE

Additionally, WatirDrops can generate a WatirModel instance from data on the page using #build

Clone this wiki locally