Module: Howitzer::Web::PageValidator::ClassMethods

Defined in:
lib/howitzer/web/page_validator.rb

Overview

This module holds page validation class methods

Instance Method Summary collapse

Instance Method Details

#matched_pagesArray

Finds all matched pages which satisfy of defined validations on current page


69
70
71
# File 'lib/howitzer/web/page_validator.rb', line 69

def matched_pages
  PageValidator.validations.keys.select { |klass| klass.opened?(sync: false) }
end

#opened?(sync: true) ⇒ Boolean

Check whether current page is opened or no

Raises:


61
62
63
64
# File 'lib/howitzer/web/page_validator.rb', line 61

def opened?(sync: true)
  return validations.all? { |(_, validation)| validation.call(self, sync) } if validations.present?
  raise Howitzer::NoValidationError, "No any page validation was found for '#{name}' page"
end

#validate(name, value, additional_value = nil) ⇒ Object

Adds validation to validation list for current page

Examples:

class ArticleListPage < Howitzer::Web::Page
  validate :title, /\ADemo web application - Listing Articles\z/
end
class ArticlePage < Howitzer::Web::Page
  validate :url, %r{\/articles\/\d+\/?\z}
end
class HomePage < Howitzer::Web::Page
  validate :element_presence, :menu_item, 'Logout'
  element :menu_item, :xpath, ->(name) { ".//a[.='#{name}']" }
end

Raises:


51
52
53
# File 'lib/howitzer/web/page_validator.rb', line 51

def validate(name, value, additional_value = nil)
  validate_by_type(name, value, additional_value)
end

#validationsHash


75
76
77
# File 'lib/howitzer/web/page_validator.rb', line 75

def validations
  PageValidator.validations[self] ||= {}
end