Class: CapybaraObjects::PageObject

Inherits:
Object
  • Object
show all
Includes:
ConvenienceMethods, InitializeMethods, LocationMethods, RegistryMethods, ScopedFinders, ValidationMethods
Defined in:
lib/capybara_objects/page_object.rb

Overview

A page object

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ScopedFinders

#get_component, #root_node, #scoped_find

Methods included from ConvenienceMethods

#click, #hover, #page

Methods included from ValidationMethods

#validate!

Constructor Details

#initialize(options = {}) ⇒ PageObject

Returns a new instance of PageObject.



33
34
35
36
# File 'lib/capybara_objects/page_object.rb', line 33

def initialize(options = {})
  super
  self.url ||= default_url
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



18
19
20
# File 'lib/capybara_objects/page_object.rb', line 18

def url
  @url
end

Class Method Details

.ptype(type) ⇒ Object

Registers a “ptype” alias for this class

Parameters:

  • The alias or type to register this class with.



22
23
24
# File 'lib/capybara_objects/page_object.rb', line 22

def ptype(type)
  registry.register_ptype type, self
end

.url(url) ⇒ Object

Defines the default url. Can be overriden in the instance

Parameters:

  • The default url



28
29
30
# File 'lib/capybara_objects/page_object.rb', line 28

def url(url)
  self.default_url = url
end

Instance Method Details

#attach(options = {}) ⇒ ::CapybaraObjects::PageObject

Attaches the page object to the current page

Returns:

  • self - allows chaining of methods



50
51
52
53
# File 'lib/capybara_objects/page_object.rb', line 50

def attach(options = {})
  validate!
  self
end

#visit::CapybaraObjects::PageObject

Visits the pre configured URL to make this page available

Returns:

  • self - allows chaining of methods

Raises:

  • ::CapybaraPageObjects::Exceptions::MissingUrl



41
42
43
44
45
46
# File 'lib/capybara_objects/page_object.rb', line 41

def visit
  raise ::CapybaraObjects::Exceptions::MissingUrl unless url.present?
  page.visit url
  validate!
  self
end