cuprite 0.12 → 0.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +14 -12
- data/lib/capybara/cuprite/browser.rb +196 -155
- data/lib/capybara/cuprite/cookie.rb +32 -32
- data/lib/capybara/cuprite/driver.rb +335 -363
- data/lib/capybara/cuprite/errors.rb +9 -8
- data/lib/capybara/cuprite/javascripts/index.js +47 -27
- data/lib/capybara/cuprite/node.rb +218 -224
- data/lib/capybara/cuprite/options.rb +14 -0
- data/lib/capybara/cuprite/page.rb +148 -154
- data/lib/capybara/cuprite/version.rb +1 -1
- data/lib/capybara/cuprite.rb +3 -0
- metadata +19 -145
@@ -9,13 +9,15 @@ module Capybara
|
|
9
9
|
|
10
10
|
def initialize(response)
|
11
11
|
@response = response
|
12
|
+
super()
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
15
16
|
class InvalidSelector < ClientError
|
16
17
|
def initialize(response, method, selector)
|
17
18
|
super(response)
|
18
|
-
@method
|
19
|
+
@method = method
|
20
|
+
@selector = selector
|
19
21
|
end
|
20
22
|
|
21
23
|
def message
|
@@ -28,14 +30,13 @@ module Capybara
|
|
28
30
|
|
29
31
|
def initialize(*)
|
30
32
|
super
|
31
|
-
data = /\A\w+: (\w+), (.+?), ([\d
|
33
|
+
data = /\A\w+: (\w+), (.+?), ([\d.-]+), ([\d.-]+)/.match(@response)
|
32
34
|
@name, @selector = data.values_at(1, 2)
|
33
35
|
@position = data.values_at(3, 4).map(&:to_f)
|
34
36
|
end
|
35
37
|
|
36
|
-
|
37
38
|
def message
|
38
|
-
"Firing a #{name} at coordinates [#{position.join(
|
39
|
+
"Firing a #{name} at coordinates [#{position.join(', ')}] failed. Cuprite detected " \
|
39
40
|
"another element with CSS selector \"#{selector}\" at this position. " \
|
40
41
|
"It may be overlapping the element you are trying to interact with. " \
|
41
42
|
"If you don't care about overlapping elements, try using node.trigger(\"#{name}\")."
|
@@ -52,10 +53,10 @@ module Capybara
|
|
52
53
|
|
53
54
|
def message
|
54
55
|
"The element you are trying to interact with is either not part of the DOM, or is " \
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
"not currently visible on the page (perhaps display: none is set). " \
|
57
|
+
"It is possible the element has been replaced by another element and you meant to interact with " \
|
58
|
+
"the new element. If so you need to do a new find in order to get a reference to the " \
|
59
|
+
"new element."
|
59
60
|
end
|
60
61
|
end
|
61
62
|
end
|
@@ -41,7 +41,7 @@ class Cuprite {
|
|
41
41
|
parents(node) {
|
42
42
|
let nodes = [];
|
43
43
|
let parent = node.parentNode;
|
44
|
-
while (parent != document) {
|
44
|
+
while (parent != document && parent !== null) {
|
45
45
|
nodes.push(parent);
|
46
46
|
parent = parent.parentNode;
|
47
47
|
}
|
@@ -84,7 +84,6 @@ class Cuprite {
|
|
84
84
|
return true;
|
85
85
|
}
|
86
86
|
|
87
|
-
|
88
87
|
isDisabled(node) {
|
89
88
|
let xpath = "parent::optgroup[@disabled] | \
|
90
89
|
ancestor::select[@disabled] | \
|
@@ -97,7 +96,7 @@ class Cuprite {
|
|
97
96
|
path(node) {
|
98
97
|
let nodes = [node];
|
99
98
|
let parent = node.parentNode;
|
100
|
-
while (parent !== document) {
|
99
|
+
while (parent !== document && parent !== null) {
|
101
100
|
nodes.unshift(parent);
|
102
101
|
parent = parent.parentNode;
|
103
102
|
}
|
@@ -151,7 +150,7 @@ class Cuprite {
|
|
151
150
|
// call the following functions in order, if one returns false (preventDefault),
|
152
151
|
// stop the call chain
|
153
152
|
[
|
154
|
-
() => this.keyupdowned(node, "keydown", keyCode),
|
153
|
+
() => this.keyupdowned(node, "keydown", char, keyCode),
|
155
154
|
() => this.keypressed(node, false, false, false, false, char.charCodeAt(0), char.charCodeAt(0)),
|
156
155
|
() => {
|
157
156
|
this.setValue(node, node.value + char)
|
@@ -159,7 +158,7 @@ class Cuprite {
|
|
159
158
|
}
|
160
159
|
].some(fn => fn())
|
161
160
|
|
162
|
-
this.keyupdowned(node, "keyup", keyCode);
|
161
|
+
this.keyupdowned(node, "keyup", char, keyCode);
|
163
162
|
}
|
164
163
|
}
|
165
164
|
|
@@ -180,19 +179,22 @@ class Cuprite {
|
|
180
179
|
}
|
181
180
|
|
182
181
|
input(node) {
|
183
|
-
let event =
|
184
|
-
event.initEvent("input", true, false);
|
182
|
+
let event = new InputEvent("input", { inputType: "insertText", bubbles: true, cancelable: false });
|
185
183
|
node.dispatchEvent(event);
|
186
184
|
}
|
187
185
|
|
188
186
|
/**
|
189
187
|
* @return {boolean} false when an event handler called preventDefault()
|
190
188
|
*/
|
191
|
-
keyupdowned(node, eventName, keyCode) {
|
192
|
-
let event =
|
193
|
-
|
194
|
-
|
195
|
-
|
189
|
+
keyupdowned(node, eventName, char, keyCode) {
|
190
|
+
let event = new KeyboardEvent(
|
191
|
+
eventName, {
|
192
|
+
bubbles: true,
|
193
|
+
cancelable: true,
|
194
|
+
key: char,
|
195
|
+
keyCode: keyCode
|
196
|
+
}
|
197
|
+
);
|
196
198
|
return !node.dispatchEvent(event);
|
197
199
|
}
|
198
200
|
|
@@ -200,15 +202,18 @@ class Cuprite {
|
|
200
202
|
* @return {boolean} false when an event handler called preventDefault()
|
201
203
|
*/
|
202
204
|
keypressed(node, altKey, ctrlKey, shiftKey, metaKey, keyCode, charCode) {
|
203
|
-
event =
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
205
|
+
let event = new KeyboardEvent(
|
206
|
+
"keypress", {
|
207
|
+
bubbles: true,
|
208
|
+
cancelable: true,
|
209
|
+
altKey: altKey,
|
210
|
+
ctrlKey: ctrlKey,
|
211
|
+
shiftKey: shiftKey,
|
212
|
+
metaKey: metaKey,
|
213
|
+
keyCode: keyCode,
|
214
|
+
charCode: charCode
|
215
|
+
}
|
216
|
+
);
|
212
217
|
return !node.dispatchEvent(event);
|
213
218
|
}
|
214
219
|
|
@@ -338,10 +343,24 @@ class Cuprite {
|
|
338
343
|
|
339
344
|
_isInViewport(node) {
|
340
345
|
let rect = node.getBoundingClientRect();
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
346
|
+
|
347
|
+
let inViewport = rect.top >= 0 &&
|
348
|
+
rect.left >= 0 &&
|
349
|
+
rect.bottom <= window.innerHeight &&
|
350
|
+
rect.right <= window.innerWidth;
|
351
|
+
|
352
|
+
if (inViewport) {
|
353
|
+
// check if obscured by another element
|
354
|
+
let x = rect.width/2;
|
355
|
+
let y = rect.height/2 ;
|
356
|
+
|
357
|
+
let px = rect.left + x,
|
358
|
+
py = rect.top + y,
|
359
|
+
e = document.elementFromPoint(px, py);
|
360
|
+
return node == e;
|
361
|
+
}
|
362
|
+
|
363
|
+
return false;
|
345
364
|
}
|
346
365
|
|
347
366
|
select(node, value) {
|
@@ -350,12 +369,13 @@ class Cuprite {
|
|
350
369
|
} else if (value == false && !node.parentNode.multiple) {
|
351
370
|
return false;
|
352
371
|
} else {
|
353
|
-
|
372
|
+
let parentNode = node.parentNode;
|
373
|
+
this.trigger(parentNode, "focus");
|
354
374
|
|
355
375
|
node.selected = value;
|
356
376
|
this.changed(node);
|
357
377
|
|
358
|
-
this.trigger(
|
378
|
+
this.trigger(parentNode, "blur");
|
359
379
|
return true;
|
360
380
|
}
|
361
381
|
}
|