Class: QAT::Web::Page Abstract

Inherits:
Object
  • Object
show all
Extended by:
Elements, Elements::Waiters, Validators
Includes:
Elements
Defined in:
lib/qat/web/page.rb,
lib/qat/web/page/validators.rb

Overview

This class is abstract.

Class to represent a Web Page. Works based on a DSL to write user friendly and powerful transition models. Two class methods are provided by this class, in order to allow the mapping of getters for page values, and also map page transitions. The use of Capybara::DSL in the implementation is recommended.

Examples:

Sample Page Object implementation for localhost:8090/example

class ExamplePage < QAT::Web::Page
  include Capybara::DSL

 def initialize
   visit 'http://localhost:8090/example'
 end

  get_value :title do
    find 'h1'
  end

  action :more_information, returns: ExampleInformationPage do
    click_link 'More information...'
    ExampleInformationPage.new
  end
end

current_page = ExamplePage.new
current_page.title # 'Example Domain'
current_page = current_page.more_information # ExampleInformationPage instance

See Also:

Since:

  • 1.0.0

Direct Known Subclasses

ProjectName::Web::Pages::Base

Defined Under Namespace

Modules: Validators

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Elements

load_elements_file

Methods included from Elements::Waiters

timeouts, timeouts_config, timeouts_file, wait_until, wait_until_not_present, wait_until_not_visible, wait_until_present, wait_until_visible

Methods included from Elements::Config

#valid_config?

Methods included from Elements::Selector

#selector

Methods included from Configuration

last_access, #last_access, last_access=, #parse_configuration

Class Method Details

.action(name, opts) { ... } ⇒ Object

Define a new method to represent a possible page transition to another page object controller. A new instance method will be defined with the given name parameter, and with the block as the method’s code to be executed. Additionally, all possible return types must be delacred in the :returns key in the opts parameter. All return types must be implementarions of QAT::Web::Page.

Parameters:

  • name (String/Symbol)

    Name of the funcion to be defined

  • opts (Hash)

    Options hash

Options Hash (opts):

  • :returns (Class/Array<Class>)

    Sublass or list of subclasses of QAT::Web::Page that can be returned by the method definition

Yields:

  • Block of code to define the getter method. The block will only be executed then the function defined by “name” is called

Yield Returns:

Since:

  • 1.0.0



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/qat/web/page.rb', line 85

def action name, opts, &block

  raise TypeError.new 'The opts parameter should be an Hash with a :returns key' unless opts.is_a? Hash

  return_value = validate_return_value(opts[:returns])

  name = name.to_sym
  define_method name, &block
  @actions       ||= {}
  @actions[name] = return_value
end

.actionsHash<Symbol, Array<QAT::Web::Page>>

Returns List of page actions and respective transition return types.

Returns:

  • (Hash<Symbol, Array<QAT::Web::Page>>)

    List of page actions and respective transition return types

Since:

  • 1.0.0



56
57
58
59
60
61
62
63
# File 'lib/qat/web/page.rb', line 56

def actions
  @actions ||= {}
  if superclass.ancestors.include? QAT::Web::Page
    superclass.actions.merge @actions
  else
    @actions
  end
end

.elementsHashWithIndifferentAccess

Returns the elements configuration

Returns:

  • (HashWithIndifferentAccess)

Since:

  • 1.0.0



116
117
118
# File 'lib/qat/web/page.rb', line 116

def elements
  @elements
end

.elements_config(elements) ⇒ HashWithIndifferentAccess

Defines elements through a configuration hash

Parameters:

  • elements (Hash)

    elements configuration

Returns:

  • (HashWithIndifferentAccess)

Since:

  • 1.0.0



109
110
111
112
# File 'lib/qat/web/page.rb', line 109

def elements_config(elements)
  valid_config?(elements, 'elements')
  @elements = HashWithIndifferentAccess.new(elements)
end

.elements_file(path) ⇒ HashWithIndifferentAccess

Loads elements configuration from a configuration file given a file path

Parameters:

  • path (String)

    path to configuration file

Returns:

  • (HashWithIndifferentAccess)

Raises:

  • (ArgumentError)

Since:

  • 1.0.0



100
101
102
103
104
# File 'lib/qat/web/page.rb', line 100

def elements_file(path)
  raise(ArgumentError, "File '#{path}' does not exist!") unless File.exist?(path)
  @elements_file = path
  elements_config(load_elements_file(@elements_file))
end

.get_value(name) { ... } ⇒ Object

Define a new method to get a value from a page. A new instance method will be defined with the given name parameter, and with the block as the method’s code to be executed. The name of the method will be added to #values

Parameters:

  • name (String/Symbol)

    Name of the funcion to be defined

Yields:

  • Block of code to define the getter method. The block will only be executed then the function defined by “name” is called

Since:

  • 1.0.0



69
70
71
72
73
74
# File 'lib/qat/web/page.rb', line 69

def get_value name, &block
  name = name.to_sym
  define_method name, &block
  @values ||= []
  @values << name
end

.valuesArray<Symbol>

Returns List of value getter functions.

Returns:

  • (Array<Symbol>)

    List of value getter functions

Since:

  • 1.0.0



45
46
47
48
49
50
51
52
# File 'lib/qat/web/page.rb', line 45

def values
  @values ||= []
  if superclass.ancestors.include? QAT::Web::Page
    @values + superclass.values
  else
    @values
  end
end

.web_collection(*args) ⇒ Object

Defines a collection of web elements identified through a given name and configuration Auxiliary methods are also dynamically defined such as the element acessor, waiters and the configuration accessor and the second an optional configuration. If none is given, it will be automatically loaded from the loaded configuration by the element name

Parameters:

  • args (Array)

    One or two arguments are expected. The first argument is the element name

See Also:

  • Capybara::Node::Finders#all

Since:

  • 1.0.0



146
147
148
149
# File 'lib/qat/web/page.rb', line 146

def web_collection(*args)
  collection = QAT::Web::Elements::Collection.new(elements, *args)
  define_web_element_methods(collection)
end

.web_element(*args) ⇒ Object

Defines a web element accessor identified through the given name and configuration Auxiliary methods are also dynamically defined such as the element acessor, waiters and the configuration accessor and the second an optional configuration. If none is given, it will be automatically loaded from the loaded configuration by the element name

Parameters:

  • args (Array)

    One or two arguments are expected. The first argument is the element name

See Also:

  • Capybara::Node::Finders#find

Since:

  • 1.0.0



126
127
128
129
# File 'lib/qat/web/page.rb', line 126

def web_element(*args)
  element = QAT::Web::Elements::Element.new(elements, *args)
  define_web_element_methods(element)
end

.web_elements(*elements) ⇒ Object

Defines a list of web element accessors identified through the given names Configuration will be automatically loaded from the loaded configuration by element name Auxiliary methods are also dynamically defined such as the element acessor, waiters and the configuration accessor

Parameters:

  • elements (Array|Symbol)

    list of names to load elements

See Also:

  • Capybara::Node::Finders#find

Since:

  • 1.0.0



136
137
138
# File 'lib/qat/web/page.rb', line 136

def web_elements(*elements)
  elements.each { |element| web_element(element) }
end

Instance Method Details

#elementsHashWithIndifferentAccess

Returns the elements configuration

Returns:

  • (HashWithIndifferentAccess)

Since:

  • 1.0.0



154
155
156
# File 'lib/qat/web/page.rb', line 154

def elements
  self.class.elements
end