Class: Capybara::Driver::RackTest::Node

Inherits:
Node
  • Object
show all
Defined in:
lib/capybara/driver/rack_test_driver.rb

Direct Known Subclasses

Form

Instance Attribute Summary

Attributes inherited from Node

#driver, #node

Instance Method Summary collapse

Methods inherited from Node

#drag_to, #initialize, #value

Methods included from Searchable

#all, #find, #find_button, #find_by_id, #find_field, #find_link

Constructor Details

This class inherits a constructor from Capybara::Node

Instance Method Details

#[](name) ⇒ Object



12
13
14
15
# File 'lib/capybara/driver/rack_test_driver.rb', line 12

def [](name)
  value = node[name.to_s]
  return value.to_s if value
end

#clickObject



39
40
41
42
43
44
45
# File 'lib/capybara/driver/rack_test_driver.rb', line 39

def click
  if tag_name == 'a'
    driver.visit(self[:href].to_s)
  elsif (tag_name == 'input' or tag_name == 'button') and %w(submit image).include?(type)
    Form.new(driver, form).submit(self)
  end
end

#pathObject



55
56
57
# File 'lib/capybara/driver/rack_test_driver.rb', line 55

def path
  node.path
end

#select(option) ⇒ Object



34
35
36
37
# File 'lib/capybara/driver/rack_test_driver.rb', line 34

def select(option)
  node.xpath(".//option").each { |node| node.remove_attribute("selected") }
  node.xpath(".//option[contains(.,'#{option}')]").first["selected"] = 'selected'
end

#set(value) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/capybara/driver/rack_test_driver.rb', line 17

def set(value)
  if tag_name == 'input' and %w(text password hidden file).include?(type)
    node['value'] = value.to_s
  elsif tag_name == 'input' and type == 'radio'
    driver.html.xpath("//input[@name='#{self[:name]}']").each { |node| node.remove_attribute("checked") }
    node['checked'] = 'checked'
  elsif tag_name == 'input' and type == 'checkbox'
    if value
      node['checked'] = 'checked'
    else
      node.remove_attribute('checked')
    end
  elsif tag_name == "textarea"
    node.content = value.to_s
  end
end

#tag_nameObject



47
48
49
# File 'lib/capybara/driver/rack_test_driver.rb', line 47

def tag_name
  node.node_name
end

#textObject



8
9
10
# File 'lib/capybara/driver/rack_test_driver.rb', line 8

def text
  node.text
end

#visible?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/capybara/driver/rack_test_driver.rb', line 51

def visible?
  node.xpath("./ancestor-or-self::*[contains(@style, 'display:none')]").size == 0
end