Class: QAT::Web::Page Abstract
- Inherits:
-
Object
- Object
- QAT::Web::Page
- Extended by:
- Elements, Elements::Waiters, Validators
- Includes:
- Elements
- Defined in:
- lib/qat/web/page.rb,
lib/qat/web/page/validators.rb
Overview
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.
Direct Known Subclasses
Defined Under Namespace
Modules: Validators
Class Method Summary collapse
-
.action(name, opts) { ... } ⇒ Object
Define a new method to represent a possible page transition to another page object controller.
-
.actions ⇒ Hash<Symbol, Array<QAT::Web::Page>>
List of page actions and respective transition return types.
-
.elements ⇒ HashWithIndifferentAccess
Returns the elements configuration.
-
.elements_config(elements) ⇒ HashWithIndifferentAccess
Defines elements through a configuration hash.
-
.elements_file(path) ⇒ HashWithIndifferentAccess
Loads elements configuration from a configuration file given a file path.
-
.get_value(name) { ... } ⇒ Object
Define a new method to get a value from a page.
-
.values ⇒ Array<Symbol>
List of value getter functions.
-
.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.
-
.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.
-
.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.
Instance Method Summary collapse
-
#elements ⇒ HashWithIndifferentAccess
Returns the elements configuration.
Methods included from Elements
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
Methods included from Elements::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.
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 |
.actions ⇒ Hash<Symbol, Array<QAT::Web::Page>>
Returns List of page actions and respective transition return types.
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 |
.elements ⇒ HashWithIndifferentAccess
Returns the elements configuration
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
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
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
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 |
.values ⇒ Array<Symbol>
Returns List of value getter functions.
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
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
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
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
#elements ⇒ HashWithIndifferentAccess
Returns the elements configuration
154 155 156 |
# File 'lib/qat/web/page.rb', line 154 def elements self.class.elements end |