poltergeist 1.16.0 → 1.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +7 -2
- data/lib/capybara/poltergeist.rb +2 -0
- data/lib/capybara/poltergeist/browser.rb +8 -1
- data/lib/capybara/poltergeist/client.rb +3 -1
- data/lib/capybara/poltergeist/client/browser.coffee +27 -10
- data/lib/capybara/poltergeist/client/compiled/browser.js +41 -11
- data/lib/capybara/poltergeist/client/compiled/main.js +17 -0
- data/lib/capybara/poltergeist/client/compiled/web_page.js +38 -2
- data/lib/capybara/poltergeist/client/main.coffee +4 -0
- data/lib/capybara/poltergeist/client/web_page.coffee +43 -1
- data/lib/capybara/poltergeist/command.rb +3 -1
- data/lib/capybara/poltergeist/cookie.rb +2 -0
- data/lib/capybara/poltergeist/driver.rb +9 -2
- data/lib/capybara/poltergeist/errors.rb +9 -0
- data/lib/capybara/poltergeist/inspector.rb +2 -0
- data/lib/capybara/poltergeist/network_traffic.rb +2 -0
- data/lib/capybara/poltergeist/network_traffic/error.rb +2 -0
- data/lib/capybara/poltergeist/network_traffic/request.rb +2 -0
- data/lib/capybara/poltergeist/network_traffic/response.rb +2 -0
- data/lib/capybara/poltergeist/node.rb +2 -0
- data/lib/capybara/poltergeist/server.rb +2 -0
- data/lib/capybara/poltergeist/utility.rb +2 -0
- data/lib/capybara/poltergeist/version.rb +3 -1
- data/lib/capybara/poltergeist/web_socket_server.rb +2 -0
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 06e484be00352d4b5c8134794b51783cd4358f6c8888ae35a4a0b396e33dd023
|
4
|
+
data.tar.gz: 1dd2652dac23268d7ef3de4d30f0222e9c720491f1a3d4b83a37dc7aa0b07982
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa6b9d400580c3b99fe73523f330a1a222c30dd2679c376bbdf4a722e966dfef8367983657c68868ef67b0650928109881d7b3d4fb0dbdacc71aca8ab5f6e43f
|
7
|
+
data.tar.gz: feb9e85896493c42f85332cdae4ad2ac570489069b7fefc9ec9c3d40efb4db94fbfe185f23163bf5512113fdeefeab67386ee238c32ff0082b951a50628ff39a
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ provided by [PhantomJS](http://phantomjs.org/).
|
|
9
9
|
**If you're viewing this at https://github.com/teampoltergeist/poltergeist,
|
10
10
|
you're reading the documentation for the master branch.
|
11
11
|
[View documentation for the latest release
|
12
|
-
(1.
|
12
|
+
(1.17.0).](https://github.com/teampoltergeist/poltergeist/tree/v1.17.0)**
|
13
13
|
|
14
14
|
## Getting help ##
|
15
15
|
|
@@ -80,13 +80,18 @@ guide](http://phantomjs.org/build.html).)
|
|
80
80
|
|
81
81
|
## Compatibility ##
|
82
82
|
|
83
|
-
Poltergeist runs on MRI 1.9
|
83
|
+
Poltergeist runs on MRI 1.9+, JRuby 1.9+ and Rubinius 1.9+. Poltergeist
|
84
84
|
and PhantomJS are currently supported on Mac OS X, Linux, and Windows
|
85
85
|
platforms.
|
86
86
|
|
87
87
|
Ruby 1.8 is no longer supported. The last release to support Ruby 1.8
|
88
88
|
was 1.0.2, so you should use that if you still need Ruby 1.8 support.
|
89
89
|
|
90
|
+
PhantomJS does not support ES6 features at the time of writing this
|
91
|
+
document. Setting `js_errors` to `true` can help determine if failing
|
92
|
+
tests require Polyfills, although a bug in PhantomJS can cause silent
|
93
|
+
failures if using ES6 features like `let`, `const`, etc.
|
94
|
+
|
90
95
|
## Running on a CI ##
|
91
96
|
|
92
97
|
There are no special steps to take. You don't need Xvfb or any running X
|
data/lib/capybara/poltergeist.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "capybara/poltergeist/errors"
|
2
4
|
require "capybara/poltergeist/command"
|
3
5
|
require 'json'
|
@@ -11,6 +13,7 @@ module Capybara::Poltergeist
|
|
11
13
|
'Poltergeist.InvalidSelector' => InvalidSelector,
|
12
14
|
'Poltergeist.StatusFailError' => StatusFailError,
|
13
15
|
'Poltergeist.NoSuchWindowError' => NoSuchWindowError,
|
16
|
+
'Poltergeist.ScriptTimeoutError' => ScriptTimeoutError,
|
14
17
|
'Poltergeist.UnsupportedFeature' => UnsupportedFeature,
|
15
18
|
'Poltergeist.KeyError' => KeyError,
|
16
19
|
}
|
@@ -125,6 +128,10 @@ module Capybara::Poltergeist
|
|
125
128
|
command 'evaluate', script, *args
|
126
129
|
end
|
127
130
|
|
131
|
+
def evaluate_async(script, wait_time, *args)
|
132
|
+
command 'evaluate_async', script, wait_time, *args
|
133
|
+
end
|
134
|
+
|
128
135
|
def execute(script, *args)
|
129
136
|
command 'execute', script, *args
|
130
137
|
end
|
@@ -141,7 +148,7 @@ module Capybara::Poltergeist
|
|
141
148
|
command 'pop_frame'
|
142
149
|
end
|
143
150
|
|
144
|
-
def switch_to_frame(handle
|
151
|
+
def switch_to_frame(handle)
|
145
152
|
case handle
|
146
153
|
when Capybara::Node::Base
|
147
154
|
command 'push_frame', [handle.native.page_id, handle.native.id]
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "timeout"
|
2
4
|
require "capybara/poltergeist/utility"
|
3
5
|
require 'cliver'
|
@@ -65,7 +67,7 @@ module Capybara::Poltergeist
|
|
65
67
|
end
|
66
68
|
}
|
67
69
|
|
68
|
-
process_options = {}
|
70
|
+
process_options = {in: File::NULL}
|
69
71
|
process_options[:pgroup] = true unless Capybara::Poltergeist.windows?
|
70
72
|
process_options[:out] = @write_io if Capybara::Poltergeist.mri?
|
71
73
|
|
@@ -31,31 +31,36 @@ class Poltergeist.Browser
|
|
31
31
|
@confirm_processes = []
|
32
32
|
@prompt_responses = []
|
33
33
|
|
34
|
+
@setupPageHandlers(@page)
|
34
35
|
|
35
|
-
|
36
|
+
return
|
37
|
+
|
38
|
+
setupPageHandlers: (page) ->
|
39
|
+
page.native().onAlert = (msg) =>
|
36
40
|
@setModalMessage msg
|
37
41
|
return
|
38
42
|
|
39
|
-
|
43
|
+
page.native().onConfirm = (msg) =>
|
40
44
|
process = @confirm_processes.pop()
|
41
45
|
process = true if process == undefined
|
42
46
|
@setModalMessage msg
|
43
47
|
return process
|
44
48
|
|
45
|
-
|
49
|
+
page.native().onPrompt = (msg, defaultVal) =>
|
46
50
|
response = @prompt_responses.pop()
|
47
51
|
response = defaultVal if (response == undefined || response == false)
|
48
52
|
|
49
53
|
@setModalMessage msg
|
50
54
|
return response
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
@
|
56
|
+
page.onPageCreated = (newPage) =>
|
57
|
+
_page = new Poltergeist.WebPage(newPage)
|
58
|
+
_page.handle = "#{@_counter++}"
|
59
|
+
_page.urlBlacklist = page.urlBlacklist
|
60
|
+
_page.urlWhitelist = page.urlWhitelist
|
61
|
+
_page.setViewportSize(page.viewportSize())
|
62
|
+
@setupPageHandlers(_page)
|
63
|
+
@pages.push(_page)
|
59
64
|
|
60
65
|
return
|
61
66
|
|
@@ -208,6 +213,18 @@ class Poltergeist.Browser
|
|
208
213
|
throw new Poltergeist.ObsoleteNode if arg["ELEMENT"]["page_id"] != @currentPage.id
|
209
214
|
@current_command.sendResponse @currentPage.evaluate("function() { return #{script} }", args...)
|
210
215
|
|
216
|
+
evaluate_async: (script, max_wait, args...) ->
|
217
|
+
for arg in args when @_isElementArgument(arg)
|
218
|
+
throw new Poltergeist.ObsoleteNode if arg["ELEMENT"]["page_id"] != @currentPage.id
|
219
|
+
command = @current_command
|
220
|
+
cb = (result)=>
|
221
|
+
command.sendResponse(result)
|
222
|
+
@currentPage.evaluate_async("function() { #{script} }", cb, args...)
|
223
|
+
setTimeout(=>
|
224
|
+
command.sendError(new Poltergeist.ScriptTimeoutError)
|
225
|
+
, max_wait*1000)
|
226
|
+
|
227
|
+
|
211
228
|
execute: (script, args...) ->
|
212
229
|
for arg in args when @_isElementArgument(arg)
|
213
230
|
throw new Poltergeist.ObsoleteNode if arg["ELEMENT"]["page_id"] != @currentPage.id
|
@@ -37,12 +37,16 @@ Poltergeist.Browser = (function() {
|
|
37
37
|
this.processed_modal_messages = [];
|
38
38
|
this.confirm_processes = [];
|
39
39
|
this.prompt_responses = [];
|
40
|
-
this.
|
40
|
+
this.setupPageHandlers(this.page);
|
41
|
+
};
|
42
|
+
|
43
|
+
Browser.prototype.setupPageHandlers = function(page) {
|
44
|
+
page["native"]().onAlert = (function(_this) {
|
41
45
|
return function(msg) {
|
42
46
|
_this.setModalMessage(msg);
|
43
47
|
};
|
44
48
|
})(this);
|
45
|
-
|
49
|
+
page["native"]().onConfirm = (function(_this) {
|
46
50
|
return function(msg) {
|
47
51
|
var process;
|
48
52
|
process = _this.confirm_processes.pop();
|
@@ -53,7 +57,7 @@ Poltergeist.Browser = (function() {
|
|
53
57
|
return process;
|
54
58
|
};
|
55
59
|
})(this);
|
56
|
-
|
60
|
+
page["native"]().onPrompt = (function(_this) {
|
57
61
|
return function(msg, defaultVal) {
|
58
62
|
var response;
|
59
63
|
response = _this.prompt_responses.pop();
|
@@ -64,15 +68,16 @@ Poltergeist.Browser = (function() {
|
|
64
68
|
return response;
|
65
69
|
};
|
66
70
|
})(this);
|
67
|
-
|
71
|
+
page.onPageCreated = (function(_this) {
|
68
72
|
return function(newPage) {
|
69
|
-
var
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
73
|
+
var _page;
|
74
|
+
_page = new Poltergeist.WebPage(newPage);
|
75
|
+
_page.handle = "" + (_this._counter++);
|
76
|
+
_page.urlBlacklist = page.urlBlacklist;
|
77
|
+
_page.urlWhitelist = page.urlWhitelist;
|
78
|
+
_page.setViewportSize(page.viewportSize());
|
79
|
+
_this.setupPageHandlers(_page);
|
80
|
+
return _this.pages.push(_page);
|
76
81
|
};
|
77
82
|
})(this);
|
78
83
|
};
|
@@ -266,6 +271,31 @@ Poltergeist.Browser = (function() {
|
|
266
271
|
return this.current_command.sendResponse((ref = this.currentPage).evaluate.apply(ref, ["function() { return " + script + " }"].concat(slice.call(args))));
|
267
272
|
};
|
268
273
|
|
274
|
+
Browser.prototype.evaluate_async = function() {
|
275
|
+
var arg, args, cb, command, i, len, max_wait, ref, script;
|
276
|
+
script = arguments[0], max_wait = arguments[1], args = 3 <= arguments.length ? slice.call(arguments, 2) : [];
|
277
|
+
for (i = 0, len = args.length; i < len; i++) {
|
278
|
+
arg = args[i];
|
279
|
+
if (this._isElementArgument(arg)) {
|
280
|
+
if (arg["ELEMENT"]["page_id"] !== this.currentPage.id) {
|
281
|
+
throw new Poltergeist.ObsoleteNode;
|
282
|
+
}
|
283
|
+
}
|
284
|
+
}
|
285
|
+
command = this.current_command;
|
286
|
+
cb = (function(_this) {
|
287
|
+
return function(result) {
|
288
|
+
return command.sendResponse(result);
|
289
|
+
};
|
290
|
+
})(this);
|
291
|
+
(ref = this.currentPage).evaluate_async.apply(ref, ["function() { " + script + " }", cb].concat(slice.call(args)));
|
292
|
+
return setTimeout((function(_this) {
|
293
|
+
return function() {
|
294
|
+
return command.sendError(new Poltergeist.ScriptTimeoutError);
|
295
|
+
};
|
296
|
+
})(this), max_wait * 1000);
|
297
|
+
};
|
298
|
+
|
269
299
|
Browser.prototype.execute = function() {
|
270
300
|
var arg, args, i, len, ref, script;
|
271
301
|
script = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
@@ -214,6 +214,23 @@ Poltergeist.NoSuchWindowError = (function(superClass) {
|
|
214
214
|
|
215
215
|
})(Poltergeist.Error);
|
216
216
|
|
217
|
+
Poltergeist.ScriptTimeoutError = (function(superClass) {
|
218
|
+
extend(ScriptTimeoutError, superClass);
|
219
|
+
|
220
|
+
function ScriptTimeoutError() {
|
221
|
+
return ScriptTimeoutError.__super__.constructor.apply(this, arguments);
|
222
|
+
}
|
223
|
+
|
224
|
+
ScriptTimeoutError.prototype.name = "Poltergeist.ScriptTimeoutError";
|
225
|
+
|
226
|
+
ScriptTimeoutError.prototype.args = function() {
|
227
|
+
return [];
|
228
|
+
};
|
229
|
+
|
230
|
+
return ScriptTimeoutError;
|
231
|
+
|
232
|
+
})(Poltergeist.Error);
|
233
|
+
|
217
234
|
Poltergeist.UnsupportedFeature = (function(superClass) {
|
218
235
|
extend(UnsupportedFeature, superClass);
|
219
236
|
|
@@ -1,11 +1,12 @@
|
|
1
|
-
var
|
1
|
+
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
2
|
+
slice = [].slice,
|
2
3
|
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
|
3
4
|
hasProp = {}.hasOwnProperty;
|
4
5
|
|
5
6
|
Poltergeist.WebPage = (function() {
|
6
7
|
var command, delegate, fn1, fn2, i, j, len, len1, ref, ref1;
|
7
8
|
|
8
|
-
WebPage.CALLBACKS = ['onConsoleMessage', 'onError', 'onLoadFinished', 'onInitialized', 'onLoadStarted', 'onResourceRequested', 'onResourceReceived', 'onResourceError', 'onNavigationRequested', 'onUrlChanged', 'onPageCreated', 'onClosing'];
|
9
|
+
WebPage.CALLBACKS = ['onConsoleMessage', 'onError', 'onLoadFinished', 'onInitialized', 'onLoadStarted', 'onResourceRequested', 'onResourceReceived', 'onResourceError', 'onNavigationRequested', 'onUrlChanged', 'onPageCreated', 'onClosing', 'onCallback'];
|
9
10
|
|
10
11
|
WebPage.DELEGATES = ['open', 'sendEvent', 'uploadFile', 'render', 'close', 'renderBase64', 'goBack', 'goForward', 'reload'];
|
11
12
|
|
@@ -16,6 +17,7 @@ Poltergeist.WebPage = (function() {
|
|
16
17
|
function WebPage(_native) {
|
17
18
|
var callback, i, len, ref;
|
18
19
|
this._native = _native;
|
20
|
+
this._checkForAsyncResult = bind(this._checkForAsyncResult, this);
|
19
21
|
this._native || (this._native = require('webpage').create());
|
20
22
|
this.id = 0;
|
21
23
|
this.source = null;
|
@@ -30,6 +32,8 @@ Poltergeist.WebPage = (function() {
|
|
30
32
|
this._requestedResources = {};
|
31
33
|
this._responseHeaders = [];
|
32
34
|
this._tempHeadersToRemoveOnRedirect = {};
|
35
|
+
this._asyncResults = {};
|
36
|
+
this._asyncEvaluationId = 0;
|
33
37
|
ref = WebPage.CALLBACKS;
|
34
38
|
for (i = 0, len = ref.length; i < len; i++) {
|
35
39
|
callback = ref[i];
|
@@ -119,6 +123,11 @@ Poltergeist.WebPage = (function() {
|
|
119
123
|
return true;
|
120
124
|
};
|
121
125
|
|
126
|
+
WebPage.prototype.onCallbackNative = function(data) {
|
127
|
+
this._asyncResults[data['command_id']] = data['command_result'];
|
128
|
+
return true;
|
129
|
+
};
|
130
|
+
|
122
131
|
WebPage.prototype.onResourceRequestedNative = function(request, net) {
|
123
132
|
var ref2;
|
124
133
|
this._networkTraffic[request.id] = {
|
@@ -568,6 +577,20 @@ Poltergeist.WebPage = (function() {
|
|
568
577
|
return result;
|
569
578
|
};
|
570
579
|
|
580
|
+
WebPage.prototype.evaluate_async = function() {
|
581
|
+
var args, callback, cb, command_id, fn, ref2;
|
582
|
+
fn = arguments[0], callback = arguments[1], args = 3 <= arguments.length ? slice.call(arguments, 2) : [];
|
583
|
+
command_id = ++this._asyncEvaluationId;
|
584
|
+
cb = callback;
|
585
|
+
this.injectAgent();
|
586
|
+
(ref2 = this["native"]()).evaluate.apply(ref2, ["function(){ var page_id = arguments[0]; var args = []; for(var i=1; i < arguments.length; i++){ if ((typeof(arguments[i]) == 'object') && (typeof(arguments[i]['ELEMENT']) == 'object')){ args.push(window.__poltergeist.get(arguments[i]['ELEMENT']['id']).element); } else { args.push(arguments[i]) } } args.push(function(result){ result = window.__poltergeist.wrapResults(result, page_id); window.callPhantom( { command_id: " + command_id + ", command_result: result } ); }); " + (this.stringifyCall(fn, "args")) + "; return}", this.id].concat(slice.call(args)));
|
587
|
+
setTimeout((function(_this) {
|
588
|
+
return function() {
|
589
|
+
return _this._checkForAsyncResult(command_id, cb);
|
590
|
+
};
|
591
|
+
})(this), 10);
|
592
|
+
};
|
593
|
+
|
571
594
|
WebPage.prototype.execute = function() {
|
572
595
|
var args, fn, ref2;
|
573
596
|
fn = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
@@ -643,6 +666,19 @@ Poltergeist.WebPage = (function() {
|
|
643
666
|
}
|
644
667
|
};
|
645
668
|
|
669
|
+
WebPage.prototype._checkForAsyncResult = function(command_id, callback) {
|
670
|
+
if (this._asyncResults.hasOwnProperty(command_id)) {
|
671
|
+
callback(this._asyncResults[command_id]);
|
672
|
+
delete this._asyncResults[command_id];
|
673
|
+
} else {
|
674
|
+
setTimeout((function(_this) {
|
675
|
+
return function() {
|
676
|
+
return _this._checkForAsyncResult(command_id, callback);
|
677
|
+
};
|
678
|
+
})(this), 50);
|
679
|
+
}
|
680
|
+
};
|
681
|
+
|
646
682
|
WebPage.prototype._blockRequest = function(url) {
|
647
683
|
var blacklisted, useWhitelist, whitelisted;
|
648
684
|
useWhitelist = this.urlWhitelist.length > 0;
|
@@ -74,6 +74,10 @@ class Poltergeist.NoSuchWindowError extends Poltergeist.Error
|
|
74
74
|
name: "Poltergeist.NoSuchWindowError"
|
75
75
|
args: -> []
|
76
76
|
|
77
|
+
class Poltergeist.ScriptTimeoutError extends Poltergeist.Error
|
78
|
+
name: "Poltergeist.ScriptTimeoutError"
|
79
|
+
args: -> []
|
80
|
+
|
77
81
|
class Poltergeist.UnsupportedFeature extends Poltergeist.Error
|
78
82
|
constructor: (@message) ->
|
79
83
|
name: "Poltergeist.UnsupportedFeature"
|
@@ -3,7 +3,7 @@ class Poltergeist.WebPage
|
|
3
3
|
'onLoadFinished', 'onInitialized', 'onLoadStarted',
|
4
4
|
'onResourceRequested', 'onResourceReceived', 'onResourceError',
|
5
5
|
'onNavigationRequested', 'onUrlChanged', 'onPageCreated',
|
6
|
-
'onClosing']
|
6
|
+
'onClosing', 'onCallback']
|
7
7
|
|
8
8
|
@DELEGATES = ['open', 'sendEvent', 'uploadFile', 'render', 'close',
|
9
9
|
'renderBase64', 'goBack', 'goForward', 'reload']
|
@@ -29,6 +29,8 @@ class Poltergeist.WebPage
|
|
29
29
|
@_requestedResources = {}
|
30
30
|
@_responseHeaders = []
|
31
31
|
@_tempHeadersToRemoveOnRedirect = {}
|
32
|
+
@_asyncResults = {}
|
33
|
+
@_asyncEvaluationId = 0
|
32
34
|
|
33
35
|
for callback in WebPage.CALLBACKS
|
34
36
|
this.bindCallback(callback)
|
@@ -85,6 +87,10 @@ class Poltergeist.WebPage
|
|
85
87
|
@errors.push(message: message, stack: stackString)
|
86
88
|
return true
|
87
89
|
|
90
|
+
onCallbackNative: (data) ->
|
91
|
+
@_asyncResults[data['command_id']] = data['command_result']
|
92
|
+
true
|
93
|
+
|
88
94
|
onResourceRequestedNative: (request, net) ->
|
89
95
|
@_networkTraffic[request.id] = {
|
90
96
|
request: request,
|
@@ -369,6 +375,32 @@ class Poltergeist.WebPage
|
|
369
375
|
return window.__poltergeist.wrapResults(_result, page_id); }", @id, args...)
|
370
376
|
result
|
371
377
|
|
378
|
+
evaluate_async: (fn, callback, args...) ->
|
379
|
+
command_id = ++@_asyncEvaluationId
|
380
|
+
cb = callback
|
381
|
+
this.injectAgent()
|
382
|
+
this.native().evaluate("function(){
|
383
|
+
var page_id = arguments[0];
|
384
|
+
var args = [];
|
385
|
+
for(var i=1; i < arguments.length; i++){
|
386
|
+
if ((typeof(arguments[i]) == 'object') && (typeof(arguments[i]['ELEMENT']) == 'object')){
|
387
|
+
args.push(window.__poltergeist.get(arguments[i]['ELEMENT']['id']).element);
|
388
|
+
} else {
|
389
|
+
args.push(arguments[i])
|
390
|
+
}
|
391
|
+
}
|
392
|
+
args.push(function(result){
|
393
|
+
result = window.__poltergeist.wrapResults(result, page_id);
|
394
|
+
window.callPhantom( { command_id: #{command_id}, command_result: result } );
|
395
|
+
});
|
396
|
+
#{this.stringifyCall(fn, "args")};
|
397
|
+
return}", @id, args...)
|
398
|
+
|
399
|
+
setTimeout( =>
|
400
|
+
@_checkForAsyncResult(command_id, cb)
|
401
|
+
, 10)
|
402
|
+
return
|
403
|
+
|
372
404
|
execute: (fn, args...) ->
|
373
405
|
this.native().evaluate("function() {
|
374
406
|
for(var i=0; i < arguments.length; i++){
|
@@ -426,6 +458,16 @@ class Poltergeist.WebPage
|
|
426
458
|
else
|
427
459
|
throw new Poltergeist.UnsupportedFeature("clearMemoryCache is supported since PhantomJS 2.0.0")
|
428
460
|
|
461
|
+
_checkForAsyncResult: (command_id, callback)=>
|
462
|
+
if @_asyncResults.hasOwnProperty(command_id)
|
463
|
+
callback(@_asyncResults[command_id])
|
464
|
+
delete @_asyncResults[command_id]
|
465
|
+
else
|
466
|
+
setTimeout(=>
|
467
|
+
@_checkForAsyncResult(command_id, callback)
|
468
|
+
, 50)
|
469
|
+
return
|
470
|
+
|
429
471
|
_blockRequest: (url) ->
|
430
472
|
useWhitelist = @urlWhitelist.length > 0
|
431
473
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'uri'
|
2
4
|
|
3
5
|
module Capybara::Poltergeist
|
@@ -139,6 +141,11 @@ module Capybara::Poltergeist
|
|
139
141
|
unwrap_script_result(result)
|
140
142
|
end
|
141
143
|
|
144
|
+
def evaluate_async_script(script, *args)
|
145
|
+
result = browser.evaluate_async(script, session_wait_time, *args.map { |arg| arg.is_a?(Capybara::Poltergeist::Node) ? arg.native : arg})
|
146
|
+
unwrap_script_result(result)
|
147
|
+
end
|
148
|
+
|
142
149
|
def execute_script(script, *args)
|
143
150
|
browser.execute(script, *args.map { |arg| arg.is_a?(Capybara::Poltergeist::Node) ? arg.native : arg})
|
144
151
|
nil
|
@@ -148,8 +155,8 @@ module Capybara::Poltergeist
|
|
148
155
|
browser.within_frame(name, &block)
|
149
156
|
end
|
150
157
|
|
151
|
-
def switch_to_frame(locator
|
152
|
-
browser.switch_to_frame(locator
|
158
|
+
def switch_to_frame(locator)
|
159
|
+
browser.switch_to_frame(locator)
|
153
160
|
end
|
154
161
|
|
155
162
|
def current_window_handle
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Capybara
|
2
4
|
module Poltergeist
|
3
5
|
class Error < StandardError; end
|
@@ -174,6 +176,13 @@ module Capybara
|
|
174
176
|
end
|
175
177
|
end
|
176
178
|
|
179
|
+
class ScriptTimeoutError < Error
|
180
|
+
def message
|
181
|
+
"Timed out waiting for evaluated script to resturn a value"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
|
177
186
|
class DeadClient < Error
|
178
187
|
def initialize(message)
|
179
188
|
@message = message
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poltergeist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Leighton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -72,28 +72,28 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 3.
|
75
|
+
version: '3.7'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 3.
|
82
|
+
version: '3.7'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: sinatra
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "<="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '3.0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "<="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '3.0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rake
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,9 +126,9 @@ dependencies:
|
|
126
126
|
name: pdf-reader
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- - "
|
129
|
+
- - "<"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
131
|
+
version: '3.0'
|
132
132
|
- - ">="
|
133
133
|
- !ruby/object:Gem::Version
|
134
134
|
version: 1.3.3
|
@@ -136,9 +136,9 @@ dependencies:
|
|
136
136
|
prerelease: false
|
137
137
|
version_requirements: !ruby/object:Gem::Requirement
|
138
138
|
requirements:
|
139
|
-
- - "
|
139
|
+
- - "<"
|
140
140
|
- !ruby/object:Gem::Version
|
141
|
-
version: '
|
141
|
+
version: '3.0'
|
142
142
|
- - ">="
|
143
143
|
- !ruby/object:Gem::Version
|
144
144
|
version: 1.3.3
|
@@ -273,7 +273,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
273
273
|
version: '0'
|
274
274
|
requirements: []
|
275
275
|
rubyforge_project:
|
276
|
-
rubygems_version: 2.
|
276
|
+
rubygems_version: 2.7.0
|
277
277
|
signing_key:
|
278
278
|
specification_version: 4
|
279
279
|
summary: PhantomJS driver for Capybara
|