Class: Capybara::RackTest::Node

Inherits:
Driver::Node show all
Defined in:
lib/capybara/rack_test/node.rb

Direct Known Subclasses

Form

Instance Attribute Summary

Attributes inherited from Driver::Node

#driver, #native

Instance Method Summary collapse

Methods inherited from Driver::Node

#double_click, #drag_to, #hover, #initialize, #inspect, #multiple?, #readonly?, #right_click, #send_keys, #trigger

Constructor Details

This class inherits a constructor from Capybara::Driver::Node

Instance Method Details

#==(other) ⇒ Object



107
108
109
# File 'lib/capybara/rack_test/node.rb', line 107

def ==(other)
  native == other.native
end

#[](name) ⇒ Object



12
13
14
# File 'lib/capybara/rack_test/node.rb', line 12

def [](name)
  string_node[name]
end

#all_textObject



4
5
6
# File 'lib/capybara/rack_test/node.rb', line 4

def all_text
  Capybara::Helpers.normalize_whitespace(native.text)
end

#checked?Boolean



79
80
81
# File 'lib/capybara/rack_test/node.rb', line 79

def checked?
  string_node.checked?
end

#click(keys = [], offset = {}) ⇒ Object

Raises:

  • (ArgumentError)


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/capybara/rack_test/node.rb', line 55

def click(keys = [], offset = {})
  raise ArgumentError, "The RackTest driver does not support click options" unless keys.empty? && offset.empty?

  if tag_name == 'a' && !self[:href].nil?
    follow_link
  elsif (tag_name == 'input' and %w[submit image].include?(type)) or
        (tag_name == 'button' and [nil, "submit"].include?(type))
    associated_form = form
    Capybara::RackTest::Form.new(driver, associated_form).submit(self) if associated_form
  elsif tag_name == 'input' and %w[checkbox radio].include?(type)
    set(!checked?)
  elsif tag_name == 'label'
    click_label
  end
end

#disabled?Boolean



87
88
89
90
91
92
93
# File 'lib/capybara/rack_test/node.rb', line 87

def disabled?
  if %w[option optgroup].include? tag_name
    string_node.disabled? || find_xpath("parent::*[self::optgroup or self::select]")[0].disabled?
  else
    string_node.disabled? || !find_xpath("parent::fieldset[@disabled] | ancestor::*[not(self::legend) or preceding-sibling::legend][parent::fieldset[@disabled]]").empty?
  end
end

#find_css(locator) ⇒ Object



103
104
105
# File 'lib/capybara/rack_test/node.rb', line 103

def find_css(locator)
  native.css(locator, Capybara::RackTest::CSSHandlers.new).map { |n| self.class.new(driver, n) }
end

#find_xpath(locator) ⇒ Object



99
100
101
# File 'lib/capybara/rack_test/node.rb', line 99

def find_xpath(locator)
  native.xpath(locator).map { |n| self.class.new(driver, n) }
end

#pathObject



95
96
97
# File 'lib/capybara/rack_test/node.rb', line 95

def path
  native.path
end

#select_optionObject



40
41
42
43
44
45
46
# File 'lib/capybara/rack_test/node.rb', line 40

def select_option
  return if disabled?
  if select_node['multiple'] != 'multiple'
    select_node.find_xpath(".//option[@selected]").each { |node| node.native.remove_attribute("selected") }
  end
  native["selected"] = 'selected'
end

#selected?Boolean



83
84
85
# File 'lib/capybara/rack_test/node.rb', line 83

def selected?
  string_node.selected?
end

#set(value, **options) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/capybara/rack_test/node.rb', line 20

def set(value, **options)
  return if disabled? || readonly?

  warn "Options passed to Node#set but the RackTest driver doesn't support any - ignoring" unless options.empty?

  if value.is_a?(Array) && !multiple?
    raise TypeError, "Value cannot be an Array when 'multiple' attribute is not present. Not a #{value.class}"
  end

  if radio?
    set_radio(value)
  elsif checkbox?
    set_checkbox(value)
  elsif input_field?
    set_input(value)
  elsif textarea?
    native['_capybara_raw_value'] = value.to_s
  end
end

#tag_nameObject



71
72
73
# File 'lib/capybara/rack_test/node.rb', line 71

def tag_name
  native.node_name
end

#unselect_optionObject



48
49
50
51
52
53
# File 'lib/capybara/rack_test/node.rb', line 48

def unselect_option
  if select_node['multiple'] != 'multiple'
    raise Capybara::UnselectNotAllowed, "Cannot unselect option from single select box."
  end
  native.remove_attribute('selected')
end

#valueObject



16
17
18
# File 'lib/capybara/rack_test/node.rb', line 16

def value
  string_node.value
end

#visible?Boolean



75
76
77
# File 'lib/capybara/rack_test/node.rb', line 75

def visible?
  string_node.visible?
end

#visible_textObject



8
9
10
# File 'lib/capybara/rack_test/node.rb', line 8

def visible_text
  Capybara::Helpers.normalize_whitespace(unnormalized_text)
end