This repository has been archived by the owner on Mar 3, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 428
/
node.rb
156 lines (125 loc) · 2.87 KB
/
node.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
module Capybara::Webkit
class Node < Capybara::Driver::Node
def visible_text
Capybara::Helpers.normalize_whitespace(invoke("text"))
end
alias_method :text, :visible_text
def all_text
Capybara::Helpers.normalize_whitespace(invoke("allText"))
end
def [](name)
value = invoke("attribute", name)
if name == 'checked' || name == 'disabled' || name == 'multiple'
value == 'true'
else
if invoke("hasAttribute", name) == 'true'
value
else
nil
end
end
end
def value
if multiple_select?
self.find_xpath(".//option").select(&:selected?).map(&:value)
else
invoke "value"
end
end
def inner_html
invoke 'getInnerHTML'
end
def inner_html=(value)
invoke 'setInnerHTML', value
end
def set(value)
invoke "set", *[value].flatten
end
def select_option
invoke "selectOption"
end
def unselect_option
select = find_xpath("ancestor::select").first
if select.multiple_select?
invoke "unselectOption"
else
raise Capybara::UnselectNotAllowed
end
end
def click
invoke("leftClick")
end
def double_click
invoke("doubleClick")
end
def right_click
invoke("rightClick")
end
def hover
invoke("hover")
end
def drag_to(element)
invoke 'dragTo', element.native
end
def tag_name
invoke "tagName"
end
def visible?
invoke("visible") == "true"
end
def selected?
invoke("selected") == "true"
end
def checked?
self['checked']
end
def disabled?
self['disabled']
end
def path
invoke "path"
end
def submit(opts = {})
invoke "submit"
end
def trigger(event)
invoke "trigger", event
end
def find_xpath(xpath)
invoke("findXpathWithin", xpath).split(',').map do |native|
self.class.new(driver, native)
end
end
alias_method :find, :find_xpath
def find_css(selector)
invoke("findCssWithin", selector).split(',').map do |native|
self.class.new(driver, native)
end
end
def invoke(name, *args)
if allow_unattached_nodes? || attached?
browser.command "Node", name, native, *args
else
raise Capybara::Webkit::NodeNotAttachedError
end
end
def allow_unattached_nodes?
!automatic_reload?
end
def automatic_reload?
Capybara.respond_to?(:automatic_reload) && Capybara.automatic_reload
end
def attached?
browser.command("Node", "isAttached", native) == "true"
end
def browser
driver.browser
end
def multiple_select?
self.tag_name == "select" && self["multiple"]
end
def ==(other)
invoke("equals", other.native) == "true"
end
end
end