Module: Howitzer::Utils::PageValidator::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#matched_pagesObject

Finds all matched pages which are satisfy of defined validations

Returns:

  • array - page names


111
112
113
# File 'lib/howitzer/utils/page_validator.rb', line 111

def matched_pages
  PageValidator.pages.select{|klass| klass.opened? }
end

#opened?Boolean

Check whether page is opened or no

Returns:

  • boolean

Returns:

  • (Boolean)

Raises:


94
95
96
97
98
99
100
101
# File 'lib/howitzer/utils/page_validator.rb', line 94

def opened?
  validation_list = PageValidator.validations[self.name]
  if validation_list.blank?
    log.error Howitzer::NoValidationError, "No any page validation was found for '#{self.name}' page"
  else
    !validation_list.any? {|(_, validation)| !validation.call(self)}
  end
end

#validates(name, options) ⇒ Object

Adds validation to validation list

Parameters:

  • name (Symbol or String)

    Which validation type. Possible values [:url, :element_presence, :title]

  • options (Hash)

    a customizable set of options

Options Hash (options):

  • Validation (Hash)

    options :pattern => [Regexp] For :url and :title validation types :locator => [String] For :element_presence (Existing locator name)

Raises:


70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/howitzer/utils/page_validator.rb', line 70

def validates(name, options)
  log.error TypeError, "Expected options to be Hash, actual is '#{options.class}'" unless options.class == Hash
  PageValidator.validations[self.name] ||= {}
  case name.to_s.to_sym
    when :url
      validate_by_pattern(:url, options)
    when :element_presence
      validate_element options
    when :title
      validate_by_pattern(:title, options)
    else
      log.error Howitzer::UnknownValidationError, "unknown '#{name}' validation name"
  end
end