Class: SeleniumRecord::Base Abstract

Inherits:
Object
  • Object
show all
Includes:
ActionBuilder, Actions, Axis, ComponentAutoload, Configuration, Core, Html, Lookup, Preconditions, Scopes, Theme, Translations, Waits
Defined in:
lib/selenium_record/base.rb

Overview

This class is abstract.

Subclass and override #run to implement a custom Selenium object

Direct Known Subclasses

NavigationItem

Constant Summary

Constants included from Waits

Waits::DEFAULT_WAITING_TIME

Constants included from Core

Core::SUBCLASS_RESPONSABILITY

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ComponentAutoload

component_loader, extract_group, extract_namespace, extract_options, included, #method_missing, #modal_for, #panel_for, #pill_for, #tab_for, #view_for

Methods included from Translations

#trans

Methods included from Theme

#dropdown_menu_xpath, #dropdown_xpath, #find_headline, #modal_header_xpath, #section_xpath, #select_option_xpath, #select_xpath

Methods included from Html

#tag_name, #to_html

Methods included from Axis

#after?, #before?, #following_sibling_elements, #ordered?, #preceding_sibling_elements

Methods included from Preconditions

#when_clickable, #when_hidden, #when_modal_present, #when_present

Methods included from Waits

included, #wait_displayed, #wait_fade_in, #wait_hidden, #wait_js_inactive, #wait_page_load

Methods included from Scopes

#scope

Methods included from ActionBuilder

#action_builder

Methods included from Actions

#accept_popup, #choose_menu, choose_option, #clear, #click, #click_link, #click_on, #click_wait, #fill, #focus, #pop_last, #select_from_chosen, #submit, #textarea_content

Methods included from Lookup

included, #lookup, #lookup_sequence, #lookup_step

Methods included from Core

#find, #find!, #find_elements, #first_last, #load_dom, #load_dom!

Methods included from Configuration

#so_module

Constructor Details

#initialize(browser, opts = {}) ⇒ Base

Returns a new instance of Base.

Parameters:

  • opts (Hash) (defaults to: {})

    the options to create a new record

Options Hash (opts):

  • :parent_el (Selenium::WebDriver::Element)

    The parent element

  • :root_el (Selenium::WebDriver::Element)

    The root element

  • :object (PORO)

    Plain Old Ruby Object contains main info related to the record



48
49
50
51
52
53
# File 'lib/selenium_record/base.rb', line 48

def initialize(browser, opts = {})
  @browser = browser
  @parent_el = opts[:parent_el]
  @root_el = opts[:root_el]
  @object = opts[:object]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SeleniumRecord::ComponentAutoload

Instance Attribute Details

#browserObject (readonly)

Returns the value of attribute browser.



39
40
41
# File 'lib/selenium_record/base.rb', line 39

def browser
  @browser
end

#objectObject (readonly)

Returns the value of attribute object.



39
40
41
# File 'lib/selenium_record/base.rb', line 39

def object
  @object
end

#parent_elObject (readonly)

Returns the value of attribute parent_el.



39
40
41
# File 'lib/selenium_record/base.rb', line 39

def parent_el
  @parent_el
end

#root_elObject (readonly) Also known as: __rootel__

Returns the value of attribute root_el.



39
40
41
# File 'lib/selenium_record/base.rb', line 39

def root_el
  @root_el
end

Class Method Details

.extract_klass(subject, opts) ⇒ SeleniumRecord::Base

Parameters:

  • opts (Hash)

    the options for the new view created

Options Hash (opts):

  • :namespace (Module)

    The namespace in which the new view should be created

  • :suffix (String)

    The suffix to be appended to the new view class name

Returns:



93
94
95
96
97
# File 'lib/selenium_record/base.rb', line 93

def self.extract_klass(subject, opts)
  namespace = opts[:namespace] || Object
  suffix = opts[:suffix] || ''
  namespace.const_get("#{subject}#{suffix}")
end

Instance Method Details

#create_record(object, opts = {}) ⇒ Object

Creates a view in the scope of current instance based on object model

passed as parameter

Parameters:

  • object (ActiveRecord::Base)

    the object related to the new view

  • opts (Hash) (defaults to: {})

    the options for the new view created

Options Hash (opts):

  • :namespace (Module)

    The namespace in which the new view should be created

  • :suffix (String)

    The suffix to be appended to the new view class name



63
64
65
66
67
# File 'lib/selenium_record/base.rb', line 63

def create_record(object, opts = {})
  subject = opts[:subject] || object.class.name
  klass = self.class.extract_klass(subject, opts)
  klass.new(@browser, parent_el: root_el, object: object)
end

#create_record_for_action(action, opts = {}) ⇒ Object

Creates a view in the scope of current instance based on the action name

Parameters:

  • action (Symbol)
  • opts (Hash) (defaults to: {})

    the options for the new view created

Options Hash (opts):

  • :namespace (Module)

    The namespace in which the new view should be created

  • :suffix (String)

    The suffix to be appended to the new view class name



76
77
78
79
# File 'lib/selenium_record/base.rb', line 76

def create_record_for_action(action, opts = {})
  klass = self.class.extract_klass(action.to_s.camelize, opts)
  klass.new(@browser, parent_el: root_el)
end

#exist?Boolean

Returns whether the view is attached to the dom

Returns:

  • (Boolean)

    returns whether the view is attached to the dom



82
83
84
85
# File 'lib/selenium_record/base.rb', line 82

def exist?
  load_dom if respond_to? :lookup_sequence
  root_el != nil
end