Class: Capybara::RackTest::Node

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

Direct Known Subclasses

Form

Constant Summary collapse

BLOCK_ELEMENTS =
%w[p h1 h2 h3 h4 h5 h6 ol ul pre address blockquote dl div fieldset form hr noscript table].freeze

Constants included from Node::WhitespaceNormalizer

Node::WhitespaceNormalizer::BREAKING_SPACES, Node::WhitespaceNormalizer::EMPTY_LINES, Node::WhitespaceNormalizer::LEADING_SPACES, Node::WhitespaceNormalizer::LEFT_TO_RIGHT_MARK, Node::WhitespaceNormalizer::LINE_SEPERATOR, Node::WhitespaceNormalizer::NON_BREAKING_SPACE, Node::WhitespaceNormalizer::PARAGRAPH_SEPERATOR, Node::WhitespaceNormalizer::REMOVED_CHARACTERS, Node::WhitespaceNormalizer::RIGHT_TO_LEFT_MARK, Node::WhitespaceNormalizer::SQUEEZED_SPACES, Node::WhitespaceNormalizer::TRAILING_SPACES, Node::WhitespaceNormalizer::ZERO_WIDTH_SPACE

Instance Attribute Summary

Attributes inherited from Driver::Node

#driver, #initial_cache, #native

Instance Method Summary collapse

Methods included from Node::WhitespaceNormalizer

#normalize_spacing, #normalize_visible_spacing

Methods inherited from Driver::Node

#==, #double_click, #drag_to, #drop, #hover, #initialize, #inspect, #multiple?, #obscured?, #rect, #right_click, #scroll_by, #scroll_to, #send_keys, #shadow_root, #trigger

Constructor Details

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

Instance Method Details

#[](name) ⇒ Object



19
20
21
# File 'lib/capybara/rack_test/node.rb', line 19

def [](name)
  string_node[name]
end

#all_textObject



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

def all_text
  normalize_spacing(native.text)
end

#checked?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/capybara/rack_test/node.rb', line 87

def checked?
  string_node.checked?
end

#click(keys = [], **options) ⇒ Object

Raises:

  • (ArgumentError)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/capybara/rack_test/node.rb', line 61

def click(keys = [], **options)
  options.delete(:offset)
  raise ArgumentError, 'The RackTest driver does not support click options' unless keys.empty? && options.empty?

  if link?
    follow_link
  elsif submits?
    associated_form = form
    Capybara::RackTest::Form.new(driver, associated_form).submit(self) if associated_form
  elsif checkable?
    set(!checked?)
  elsif tag_name == 'label'
    click_label
  elsif (details = native.xpath('.//ancestor-or-self::details').last)
    toggle_details(details)
  end
end

#disabled?Boolean

Returns:

  • (Boolean)


95
96
97
98
99
100
101
102
103
# File 'lib/capybara/rack_test/node.rb', line 95

def disabled?
  return true if string_node.disabled?

  if %w[option optgroup].include? tag_name
    find_xpath(OPTION_OWNER_XPATH)[0].disabled?
  else
    !find_xpath(DISABLED_BY_FIELDSET_XPATH).empty?
  end
end

#find_css(locator, **_hints) ⇒ Object



120
121
122
# File 'lib/capybara/rack_test/node.rb', line 120

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

#find_xpath(locator, **_hints) ⇒ Object



116
117
118
# File 'lib/capybara/rack_test/node.rb', line 116

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

#pathObject



112
113
114
# File 'lib/capybara/rack_test/node.rb', line 112

def path
  native.path
end

#readonly?Boolean

Returns:

  • (Boolean)


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

def readonly?
  # readonly attribute not valid on these input types
  return false if input_field? && %w[hidden range color checkbox radio file submit image reset button].include?(type)

  super
end

#select_optionObject



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

def select_option
  return if disabled?

  deselect_options unless select_node.multiple?
  native['selected'] = 'selected'
end

#selected?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/capybara/rack_test/node.rb', line 91

def selected?
  string_node.selected?
end

#set(value, **options) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/capybara/rack_test/node.rb', line 31

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? then set_radio(value)
  elsif checkbox? then set_checkbox(value)
  elsif range? then set_range(value)
  elsif input_field? then set_input(value)
  elsif textarea? then native['_capybara_raw_value'] = value.to_s
  end
end

#style(_styles) ⇒ Object

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/capybara/rack_test/node.rb', line 23

def style(_styles)
  raise NotImplementedError, 'The rack_test driver does not process CSS'
end

#tag_nameObject



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

def tag_name
  native.node_name
end

#unselect_optionObject



55
56
57
58
59
# File 'lib/capybara/rack_test/node.rb', line 55

def unselect_option
  raise Capybara::UnselectNotAllowed, 'Cannot unselect option from single select box.' unless select_node.multiple?

  native.remove_attribute('selected')
end

#valueObject



27
28
29
# File 'lib/capybara/rack_test/node.rb', line 27

def value
  string_node.value
end

#visible?Boolean

Returns:

  • (Boolean)


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

def visible?
  string_node.visible?
end

#visible_textObject



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

def visible_text
  normalize_visible_spacing(displayed_text)
end