Class: Capypage::Element

Inherits:
Object
  • Object
show all
Includes:
ElementProxy
Defined in:
lib/capypage/element.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(selector, options = {}, &block) ⇒ Element

Returns a new instance of Element.



10
11
12
13
14
15
16
17
# File 'lib/capypage/element.rb', line 10

def initialize(selector, options = {}, &block)
  @finder_options = options.reverse_merge :match => :first
  @selector       = selector
  @base_element   = finder_options[:base_element]
  @select_using   = finder_options.delete(:select_using) || Capybara.default_selector

  block.call(self) if block.present?
end

Instance Attribute Details

#base_elementObject (readonly)

Returns the value of attribute base_element.



8
9
10
# File 'lib/capypage/element.rb', line 8

def base_element
  @base_element
end

#finder_optionsObject (readonly)

Returns the value of attribute finder_options.



8
9
10
# File 'lib/capypage/element.rb', line 8

def finder_options
  @finder_options
end

#select_usingObject (readonly)

Returns the value of attribute select_using.



8
9
10
# File 'lib/capypage/element.rb', line 8

def select_using
  @select_using
end

#selectorObject (readonly)

Returns the value of attribute selector.



8
9
10
# File 'lib/capypage/element.rb', line 8

def selector
  @selector
end

Instance Method Details

#element(name, selector, options = {}) ⇒ Object



19
20
21
22
# File 'lib/capypage/element.rb', line 19

def element(name, selector, options = {})
  base = self
  define_singleton_method(name) { Element.new(selector, options.merge(:base_element => base)) }
end

#elements(name, selector, options = {}, &block) ⇒ Object



24
25
26
27
# File 'lib/capypage/element.rb', line 24

def elements(name, selector, options = {}, &block)
  base = self
  define_singleton_method(name) { Elements.new(selector, options.merge(:base_element => base), &block) }
end

#not_present?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/capypage/element.rb', line 33

def not_present?
  base_element.has_no_selector? selector, capybara_finder_options
end

#present?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/capypage/element.rb', line 29

def present?
  base_element.has_selector? selector, capybara_finder_options
end

#visible?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
# File 'lib/capypage/element.rb', line 37

def visible?(options = {})
  capybara_element(options).visible?
rescue Capybara::ElementNotFound
  false
end