Class: Capybara::Driver::Grope::Node

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

Instance Method Summary collapse

Instance Method Details

#[](name) ⇒ Object



9
10
11
# File 'lib/capybara/driver/grope_driver.rb', line 9

def [](name)
  native.getAttribute(name.to_s)
end

#all(xpath) ⇒ Object



108
109
110
# File 'lib/capybara/driver/grope_driver.rb', line 108

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

#checked?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/capybara/driver/grope_driver.rb', line 88

def checked?
  native.getAttribute('checked') == "checked"
end

#clickObject



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

def click
  js.click(native)
end

#drag_to(element) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/capybara/driver/grope_driver.rb', line 51

def drag_to(element)
  js = driver.grope.eval(<<JS)
Grope.dd = function(draggable, droppable) {
var dispatchMouseEvent = function(e, type, dst) {
    var evt = document.createEvent('MouseEvents');
    var pos = getElementPosition(dst);
    evt.initMouseEvent(type, true, true, window, 0, 0, 0, pos.left, pos.top, false, false, false, false, 0, null);
    e.dispatchEvent(evt);
};
var getElementPosition = function(elem) {
    var position = elem.getBoundingClientRect();
    return {
        left: Math.round(window.scrollX+position.left),
        top: Math.round(window.scrollY+position.top),
        width: elem.clientWidth,
        height: elem.clientHeight
    };
};

dispatchMouseEvent(draggable, 'mousedown', draggable);
dispatchMouseEvent(draggable, 'mousemove', droppable);
dispatchMouseEvent(draggable, 'mouseup', droppable);
};
return Grope;
JS
  js.dd(self.native, element.native)
end

#find(xpath) ⇒ Object



104
105
106
# File 'lib/capybara/driver/grope_driver.rb', line 104

def find(xpath)
  self.class.new(driver, driver.grope.find(xpath, native))
end

#jsObject



112
113
114
# File 'lib/capybara/driver/grope_driver.rb', line 112

def js
  @js ||= driver.grope.eval('return Grope')
end

#pathObject



96
97
98
# File 'lib/capybara/driver/grope_driver.rb', line 96

def path
  # TODO
end

#select(option) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/capybara/driver/grope_driver.rb', line 25

def select(option)
  native.options.find do |o|
    o.value == option.value
  end.selected = 1
rescue
  options = native.options.map { |o| "'#{o.textContent}'" }.join(', ')
  raise Capybara::OptionNotFound, "No such option '#{option}' in this select box. Available options: #{options}"
end

#selected?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/capybara/driver/grope_driver.rb', line 92

def selected?
  native.getAttribute('selected') == "selected"
end

#set(value) ⇒ Object



21
22
23
# File 'lib/capybara/driver/grope_driver.rb', line 21

def set(value)
  native.value = value
end

#tag_nameObject



79
80
81
# File 'lib/capybara/driver/grope_driver.rb', line 79

def tag_name
  native.nodeName.downcase
end

#textObject



5
6
7
# File 'lib/capybara/driver/grope_driver.rb', line 5

def text
  native.textContent
end

#trigger(event) ⇒ Object



100
101
102
# File 'lib/capybara/driver/grope_driver.rb', line 100

def trigger(event)
  js._dispatchMouseEvent(native, event.to_s)
end

#unselect(option) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/capybara/driver/grope_driver.rb', line 34

def unselect(option)
  if native.multiple.zero?
    raise Capybara::UnselectNotAllowed, "Cannot unselect option '#{option}' from single select box."
  end

  native.options.find do |o|
    o.value == option.value
  end.selected = 0
rescue
  options = native.options.map { |o| "'#{o.textContent}'" }.join(', ')
  raise Capybara::OptionNotFound, "No such option '#{option}' in this select box. Available options: #{options}"
end

#valueObject



13
14
15
16
17
18
19
# File 'lib/capybara/driver/grope_driver.rb', line 13

def value
  if tag_name == "select" and native.multiple?
    native.selected_options
  else
    native.value
  end
end

#visible?Boolean

Returns:

  • (Boolean)


83
84
85
86
# File 'lib/capybara/driver/grope_driver.rb', line 83

def visible?
  (driver.grope.document.defaultView.getComputedStyle(native, '').visibility == 'visible') &&
    !(native.offsetWidth == 0 && native.offsetHeight == 0)
end