poltergeist 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +68 -263
- data/lib/capybara/poltergeist.rb +1 -0
- data/lib/capybara/poltergeist/browser.rb +36 -3
- data/lib/capybara/poltergeist/client.rb +32 -31
- data/lib/capybara/poltergeist/client/agent.coffee +7 -6
- data/lib/capybara/poltergeist/client/browser.coffee +47 -13
- data/lib/capybara/poltergeist/client/compiled/agent.js +6 -24
- data/lib/capybara/poltergeist/client/compiled/browser.js +76 -39
- data/lib/capybara/poltergeist/client/compiled/main.js +0 -2
- data/lib/capybara/poltergeist/client/compiled/node.js +0 -4
- data/lib/capybara/poltergeist/client/compiled/web_page.js +42 -24
- data/lib/capybara/poltergeist/client/web_page.coffee +28 -8
- data/lib/capybara/poltergeist/driver.rb +31 -5
- data/lib/capybara/poltergeist/errors.rb +19 -19
- data/lib/capybara/poltergeist/json.rb +25 -0
- data/lib/capybara/poltergeist/node.rb +1 -1
- data/lib/capybara/poltergeist/version.rb +1 -1
- data/lib/capybara/poltergeist/web_socket_server.rb +13 -76
- metadata +47 -63
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'socket'
|
2
|
-
require '
|
3
|
-
require 'http/parser'
|
4
|
-
require 'faye/websocket'
|
2
|
+
require 'websocket/driver'
|
5
3
|
|
6
4
|
module Capybara::Poltergeist
|
7
5
|
# This is a 'custom' Web Socket server that is designed to be synchronous. What
|
@@ -11,45 +9,6 @@ module Capybara::Poltergeist
|
|
11
9
|
# how Web Sockets are usually used, but it's what we want here, as we want to
|
12
10
|
# send a message to PhantomJS and then wait for it to respond).
|
13
11
|
class WebSocketServer
|
14
|
-
class FayeHandler
|
15
|
-
attr_reader :owner, :env, :parser
|
16
|
-
|
17
|
-
def initialize(owner, env)
|
18
|
-
@owner = owner
|
19
|
-
@env = env
|
20
|
-
@parser = Faye::WebSocket.parser(env).new(self)
|
21
|
-
@messages = []
|
22
|
-
end
|
23
|
-
|
24
|
-
def url
|
25
|
-
"ws://#{env['SERVER_NAME']}:#{env['SERVER_PORT']}/"
|
26
|
-
end
|
27
|
-
|
28
|
-
def handshake_response
|
29
|
-
parser.handshake_response
|
30
|
-
end
|
31
|
-
|
32
|
-
def parse(data)
|
33
|
-
parser.parse(data)
|
34
|
-
end
|
35
|
-
|
36
|
-
def encode(message)
|
37
|
-
parser.frame(Faye::WebSocket.encode(message))
|
38
|
-
end
|
39
|
-
|
40
|
-
def receive(message)
|
41
|
-
@messages << message
|
42
|
-
end
|
43
|
-
|
44
|
-
def message?
|
45
|
-
@messages.any?
|
46
|
-
end
|
47
|
-
|
48
|
-
def next_message
|
49
|
-
@messages.shift
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
12
|
# How much to try to read from the socket at once (it's kinda arbitrary because we
|
54
13
|
# just keep reading until we've received a full frame)
|
55
14
|
RECV_SIZE = 1024
|
@@ -59,12 +18,11 @@ module Capybara::Poltergeist
|
|
59
18
|
|
60
19
|
HOST = '127.0.0.1'
|
61
20
|
|
62
|
-
attr_reader :port, :
|
21
|
+
attr_reader :port, :driver, :socket, :server
|
63
22
|
attr_accessor :timeout
|
64
23
|
|
65
24
|
def initialize(port = nil, timeout = nil)
|
66
25
|
@timeout = timeout
|
67
|
-
@parser = Http::Parser.new
|
68
26
|
@server = start_server(port)
|
69
27
|
end
|
70
28
|
|
@@ -94,37 +52,16 @@ module Capybara::Poltergeist
|
|
94
52
|
# Accept a client on the TCP server socket, then receive its initial HTTP request
|
95
53
|
# and use that to initialize a Web Socket.
|
96
54
|
def accept
|
97
|
-
@socket
|
98
|
-
|
99
|
-
while msg = socket.gets
|
100
|
-
parser << msg
|
101
|
-
break if msg == "\r\n"
|
102
|
-
end
|
55
|
+
@socket = server.accept
|
56
|
+
@messages = []
|
103
57
|
|
104
|
-
@
|
105
|
-
|
58
|
+
@driver = ::WebSocket::Driver.server(self)
|
59
|
+
@driver.on(:connect) { |event| @driver.start }
|
60
|
+
@driver.on(:message) { |event| @messages << event.data }
|
106
61
|
end
|
107
62
|
|
108
|
-
|
109
|
-
|
110
|
-
# WebKit in PhantomJS uses, but it might need to change in the future.
|
111
|
-
def env
|
112
|
-
@env ||= begin
|
113
|
-
env = {
|
114
|
-
'REQUEST_METHOD' => parser.http_method,
|
115
|
-
'SCRIPT_NAME' => '',
|
116
|
-
'PATH_INFO' => '',
|
117
|
-
'QUERY_STRING' => '',
|
118
|
-
'SERVER_NAME' => '127.0.0.1',
|
119
|
-
'SERVER_PORT' => port.to_s,
|
120
|
-
'HTTP_ORIGIN' => 'http://127.0.0.1:2000/',
|
121
|
-
'rack.input' => StringIO.new(socket.read(8))
|
122
|
-
}
|
123
|
-
parser.headers.each do |header, value|
|
124
|
-
env['HTTP_' + header.upcase.gsub('-', '_')] = value
|
125
|
-
end
|
126
|
-
env
|
127
|
-
end
|
63
|
+
def write(data)
|
64
|
+
@socket.write(data)
|
128
65
|
end
|
129
66
|
|
130
67
|
# Block until the next message is available from the Web Socket.
|
@@ -132,21 +69,21 @@ module Capybara::Poltergeist
|
|
132
69
|
def receive
|
133
70
|
start = Time.now
|
134
71
|
|
135
|
-
until
|
72
|
+
until @messages.any?
|
136
73
|
raise Errno::EWOULDBLOCK if (Time.now - start) >= timeout
|
137
74
|
IO.select([socket], [], [], timeout) or raise Errno::EWOULDBLOCK
|
138
75
|
data = socket.recv(RECV_SIZE)
|
139
76
|
break if data.empty?
|
140
|
-
|
77
|
+
driver.parse(data)
|
141
78
|
end
|
142
79
|
|
143
|
-
|
80
|
+
@messages.shift
|
144
81
|
end
|
145
82
|
|
146
83
|
# Send a message and block until there is a response
|
147
84
|
def send(message)
|
148
85
|
accept unless connected?
|
149
|
-
|
86
|
+
driver.text(message)
|
150
87
|
receive
|
151
88
|
rescue Errno::EWOULDBLOCK
|
152
89
|
raise TimeoutError.new(message)
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poltergeist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.4.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jon Leighton
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-09-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: capybara
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,53 +20,55 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 2.1.0
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
28
|
+
name: websocket-driver
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: multi_json
|
32
43
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
44
|
requirements:
|
35
45
|
- - ~>
|
36
46
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0
|
47
|
+
version: '1.0'
|
38
48
|
type: :runtime
|
39
49
|
prerelease: false
|
40
50
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
51
|
requirements:
|
43
52
|
- - ~>
|
44
53
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0
|
54
|
+
version: '1.0'
|
46
55
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
56
|
+
name: cliver
|
48
57
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
58
|
requirements:
|
51
|
-
- -
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: 0.4.4
|
54
|
-
- - <
|
59
|
+
- - ~>
|
55
60
|
- !ruby/object:Gem::Version
|
56
|
-
version: 0.
|
61
|
+
version: 0.2.1
|
57
62
|
type: :runtime
|
58
63
|
prerelease: false
|
59
64
|
version_requirements: !ruby/object:Gem::Requirement
|
60
|
-
none: false
|
61
65
|
requirements:
|
62
|
-
- -
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
version: 0.4.4
|
65
|
-
- - <
|
66
|
+
- - ~>
|
66
67
|
- !ruby/object:Gem::Version
|
67
|
-
version: 0.
|
68
|
+
version: 0.2.1
|
68
69
|
- !ruby/object:Gem::Dependency
|
69
70
|
name: rspec
|
70
71
|
requirement: !ruby/object:Gem::Requirement
|
71
|
-
none: false
|
72
72
|
requirements:
|
73
73
|
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
@@ -76,7 +76,6 @@ dependencies:
|
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
79
|
requirements:
|
81
80
|
- - ~>
|
82
81
|
- !ruby/object:Gem::Version
|
@@ -84,7 +83,6 @@ dependencies:
|
|
84
83
|
- !ruby/object:Gem::Dependency
|
85
84
|
name: sinatra
|
86
85
|
requirement: !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
86
|
requirements:
|
89
87
|
- - ~>
|
90
88
|
- !ruby/object:Gem::Version
|
@@ -92,7 +90,6 @@ dependencies:
|
|
92
90
|
type: :development
|
93
91
|
prerelease: false
|
94
92
|
version_requirements: !ruby/object:Gem::Requirement
|
95
|
-
none: false
|
96
93
|
requirements:
|
97
94
|
- - ~>
|
98
95
|
- !ruby/object:Gem::Version
|
@@ -100,7 +97,6 @@ dependencies:
|
|
100
97
|
- !ruby/object:Gem::Dependency
|
101
98
|
name: rake
|
102
99
|
requirement: !ruby/object:Gem::Requirement
|
103
|
-
none: false
|
104
100
|
requirements:
|
105
101
|
- - ~>
|
106
102
|
- !ruby/object:Gem::Version
|
@@ -108,7 +104,6 @@ dependencies:
|
|
108
104
|
type: :development
|
109
105
|
prerelease: false
|
110
106
|
version_requirements: !ruby/object:Gem::Requirement
|
111
|
-
none: false
|
112
107
|
requirements:
|
113
108
|
- - ~>
|
114
109
|
- !ruby/object:Gem::Version
|
@@ -116,7 +111,6 @@ dependencies:
|
|
116
111
|
- !ruby/object:Gem::Dependency
|
117
112
|
name: image_size
|
118
113
|
requirement: !ruby/object:Gem::Requirement
|
119
|
-
none: false
|
120
114
|
requirements:
|
121
115
|
- - ~>
|
122
116
|
- !ruby/object:Gem::Version
|
@@ -124,7 +118,6 @@ dependencies:
|
|
124
118
|
type: :development
|
125
119
|
prerelease: false
|
126
120
|
version_requirements: !ruby/object:Gem::Requirement
|
127
|
-
none: false
|
128
121
|
requirements:
|
129
122
|
- - ~>
|
130
123
|
- !ruby/object:Gem::Version
|
@@ -132,7 +125,6 @@ dependencies:
|
|
132
125
|
- !ruby/object:Gem::Dependency
|
133
126
|
name: coffee-script
|
134
127
|
requirement: !ruby/object:Gem::Requirement
|
135
|
-
none: false
|
136
128
|
requirements:
|
137
129
|
- - ~>
|
138
130
|
- !ruby/object:Gem::Version
|
@@ -140,7 +132,6 @@ dependencies:
|
|
140
132
|
type: :development
|
141
133
|
prerelease: false
|
142
134
|
version_requirements: !ruby/object:Gem::Requirement
|
143
|
-
none: false
|
144
135
|
requirements:
|
145
136
|
- - ~>
|
146
137
|
- !ruby/object:Gem::Version
|
@@ -148,7 +139,6 @@ dependencies:
|
|
148
139
|
- !ruby/object:Gem::Dependency
|
149
140
|
name: guard-coffeescript
|
150
141
|
requirement: !ruby/object:Gem::Requirement
|
151
|
-
none: false
|
152
142
|
requirements:
|
153
143
|
- - ~>
|
154
144
|
- !ruby/object:Gem::Version
|
@@ -156,7 +146,6 @@ dependencies:
|
|
156
146
|
type: :development
|
157
147
|
prerelease: false
|
158
148
|
version_requirements: !ruby/object:Gem::Requirement
|
159
|
-
none: false
|
160
149
|
requirements:
|
161
150
|
- - ~>
|
162
151
|
- !ruby/object:Gem::Version
|
@@ -164,7 +153,6 @@ dependencies:
|
|
164
153
|
- !ruby/object:Gem::Dependency
|
165
154
|
name: rspec-rerun
|
166
155
|
requirement: !ruby/object:Gem::Requirement
|
167
|
-
none: false
|
168
156
|
requirements:
|
169
157
|
- - ~>
|
170
158
|
- !ruby/object:Gem::Version
|
@@ -172,7 +160,6 @@ dependencies:
|
|
172
160
|
type: :development
|
173
161
|
prerelease: false
|
174
162
|
version_requirements: !ruby/object:Gem::Requirement
|
175
|
-
none: false
|
176
163
|
requirements:
|
177
164
|
- - ~>
|
178
165
|
- !ruby/object:Gem::Version
|
@@ -184,60 +171,57 @@ executables: []
|
|
184
171
|
extensions: []
|
185
172
|
extra_rdoc_files: []
|
186
173
|
files:
|
187
|
-
- lib/capybara/poltergeist.rb
|
188
|
-
- lib/capybara/poltergeist/client.rb
|
189
|
-
- lib/capybara/poltergeist/server.rb
|
190
174
|
- lib/capybara/poltergeist/browser.rb
|
191
|
-
- lib/capybara/poltergeist/
|
192
|
-
- lib/capybara/poltergeist/
|
193
|
-
- lib/capybara/poltergeist/web_socket_server.rb
|
194
|
-
- lib/capybara/poltergeist/network_traffic/request.rb
|
195
|
-
- lib/capybara/poltergeist/network_traffic/response.rb
|
196
|
-
- lib/capybara/poltergeist/version.rb
|
197
|
-
- lib/capybara/poltergeist/driver.rb
|
198
|
-
- lib/capybara/poltergeist/utility.rb
|
199
|
-
- lib/capybara/poltergeist/client/connection.coffee
|
200
|
-
- lib/capybara/poltergeist/client/node.coffee
|
175
|
+
- lib/capybara/poltergeist/client/agent.coffee
|
176
|
+
- lib/capybara/poltergeist/client/browser.coffee
|
201
177
|
- lib/capybara/poltergeist/client/compiled/agent.js
|
202
178
|
- lib/capybara/poltergeist/client/compiled/browser.js
|
179
|
+
- lib/capybara/poltergeist/client/compiled/connection.js
|
203
180
|
- lib/capybara/poltergeist/client/compiled/main.js
|
204
181
|
- lib/capybara/poltergeist/client/compiled/node.js
|
205
|
-
- lib/capybara/poltergeist/client/compiled/connection.js
|
206
182
|
- lib/capybara/poltergeist/client/compiled/web_page.js
|
183
|
+
- lib/capybara/poltergeist/client/connection.coffee
|
207
184
|
- lib/capybara/poltergeist/client/main.coffee
|
185
|
+
- lib/capybara/poltergeist/client/node.coffee
|
208
186
|
- lib/capybara/poltergeist/client/web_page.coffee
|
209
|
-
- lib/capybara/poltergeist/client
|
210
|
-
- lib/capybara/poltergeist/client/agent.coffee
|
211
|
-
- lib/capybara/poltergeist/node.rb
|
187
|
+
- lib/capybara/poltergeist/client.rb
|
212
188
|
- lib/capybara/poltergeist/cookie.rb
|
189
|
+
- lib/capybara/poltergeist/driver.rb
|
190
|
+
- lib/capybara/poltergeist/errors.rb
|
191
|
+
- lib/capybara/poltergeist/inspector.rb
|
192
|
+
- lib/capybara/poltergeist/json.rb
|
193
|
+
- lib/capybara/poltergeist/network_traffic/request.rb
|
194
|
+
- lib/capybara/poltergeist/network_traffic/response.rb
|
213
195
|
- lib/capybara/poltergeist/network_traffic.rb
|
196
|
+
- lib/capybara/poltergeist/node.rb
|
197
|
+
- lib/capybara/poltergeist/server.rb
|
198
|
+
- lib/capybara/poltergeist/utility.rb
|
199
|
+
- lib/capybara/poltergeist/version.rb
|
200
|
+
- lib/capybara/poltergeist/web_socket_server.rb
|
201
|
+
- lib/capybara/poltergeist.rb
|
214
202
|
- LICENSE
|
215
203
|
- README.md
|
216
204
|
homepage: http://github.com/jonleighton/poltergeist
|
217
205
|
licenses: []
|
206
|
+
metadata: {}
|
218
207
|
post_install_message:
|
219
208
|
rdoc_options: []
|
220
209
|
require_paths:
|
221
210
|
- lib
|
222
211
|
required_ruby_version: !ruby/object:Gem::Requirement
|
223
|
-
none: false
|
224
212
|
requirements:
|
225
|
-
- -
|
213
|
+
- - '>='
|
226
214
|
- !ruby/object:Gem::Version
|
227
215
|
version: 1.9.2
|
228
216
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
229
|
-
none: false
|
230
217
|
requirements:
|
231
|
-
- -
|
218
|
+
- - '>='
|
232
219
|
- !ruby/object:Gem::Version
|
233
220
|
version: '0'
|
234
|
-
segments:
|
235
|
-
- 0
|
236
|
-
hash: 4058260924079530296
|
237
221
|
requirements: []
|
238
222
|
rubyforge_project:
|
239
|
-
rubygems_version:
|
223
|
+
rubygems_version: 2.0.3
|
240
224
|
signing_key:
|
241
|
-
specification_version:
|
225
|
+
specification_version: 4
|
242
226
|
summary: PhantomJS driver for Capybara
|
243
227
|
test_files: []
|