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

#drag_to, #initialize, #inspect, #trigger

Constructor Details

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

Instance Method Details

#[](name) ⇒ Object



6
7
8
# File 'lib/capybara/rack_test/node.rb', line 6

def [](name)
  string_node[name]
end

#checked?Boolean



67
68
69
# File 'lib/capybara/rack_test/node.rb', line 67

def checked?
  string_node.checked?
end

#clickObject



49
50
51
52
53
54
55
56
57
# File 'lib/capybara/rack_test/node.rb', line 49

def click
  if tag_name == 'a'
    method = self["data-method"] || :get
    driver.follow(method, self[:href].to_s)
  elsif (tag_name == 'input' and %w(submit image).include?(type)) or
      ((tag_name == 'button') and type.nil? or type == "submit")
    Capybara::RackTest::Form.new(driver, form).submit(self)
  end
end

#find(locator) ⇒ Object



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

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

#pathObject



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

def path
  native.path
end

#select_optionObject



35
36
37
38
39
40
# File 'lib/capybara/rack_test/node.rb', line 35

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

#selected?Boolean



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

def selected?
  string_node.selected?
end

#set(value) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/capybara/rack_test/node.rb', line 14

def set(value)
  if tag_name == 'input' and type == 'radio'
    other_radios_xpath = XPath.generate { |x| x.anywhere(:input)[x.attr(:name).equals(self[:name])] }.to_s
    driver.dom.xpath(other_radios_xpath).each { |node| node.remove_attribute("checked") }
    native['checked'] = 'checked'
  elsif tag_name == 'input' and type == 'checkbox'
    if value && !native['checked']
      native['checked'] = 'checked'
    elsif !value && native['checked']
      native.remove_attribute('checked')
    end
  elsif tag_name == 'input'
    if (type == 'text' || type == 'password') && self[:maxlength]
      value = value[0...self[:maxlength].to_i]
    end
    native['value'] = value.to_s
  elsif tag_name == "textarea"
    native.content = value.to_s
  end
end

#tag_nameObject



59
60
61
# File 'lib/capybara/rack_test/node.rb', line 59

def tag_name
  native.node_name
end

#textObject



2
3
4
# File 'lib/capybara/rack_test/node.rb', line 2

def text
  native.text
end

#unselect_optionObject



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

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



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

def value
  string_node.value
end

#visible?Boolean



63
64
65
# File 'lib/capybara/rack_test/node.rb', line 63

def visible?
  string_node.visible?
end