poltergeistFork 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +22 -0
  3. data/README.md +425 -0
  4. data/lib/capybara/poltergeist/browser.rb +426 -0
  5. data/lib/capybara/poltergeist/client.rb +151 -0
  6. data/lib/capybara/poltergeist/client/agent.coffee +423 -0
  7. data/lib/capybara/poltergeist/client/browser.coffee +497 -0
  8. data/lib/capybara/poltergeist/client/cmd.coffee +17 -0
  9. data/lib/capybara/poltergeist/client/compiled/agent.js +587 -0
  10. data/lib/capybara/poltergeist/client/compiled/browser.js +687 -0
  11. data/lib/capybara/poltergeist/client/compiled/cmd.js +31 -0
  12. data/lib/capybara/poltergeist/client/compiled/connection.js +25 -0
  13. data/lib/capybara/poltergeist/client/compiled/main.js +228 -0
  14. data/lib/capybara/poltergeist/client/compiled/node.js +88 -0
  15. data/lib/capybara/poltergeist/client/compiled/web_page.js +539 -0
  16. data/lib/capybara/poltergeist/client/connection.coffee +11 -0
  17. data/lib/capybara/poltergeist/client/main.coffee +99 -0
  18. data/lib/capybara/poltergeist/client/node.coffee +70 -0
  19. data/lib/capybara/poltergeist/client/pre/agent.js +587 -0
  20. data/lib/capybara/poltergeist/client/pre/browser.js +688 -0
  21. data/lib/capybara/poltergeist/client/pre/cmd.js +31 -0
  22. data/lib/capybara/poltergeist/client/pre/connection.js +25 -0
  23. data/lib/capybara/poltergeist/client/pre/main.js +228 -0
  24. data/lib/capybara/poltergeist/client/pre/node.js +88 -0
  25. data/lib/capybara/poltergeist/client/pre/web_page.js +540 -0
  26. data/lib/capybara/poltergeist/client/web_page.coffee +372 -0
  27. data/lib/capybara/poltergeist/command.rb +17 -0
  28. data/lib/capybara/poltergeist/cookie.rb +35 -0
  29. data/lib/capybara/poltergeist/driver.rb +394 -0
  30. data/lib/capybara/poltergeist/errors.rb +183 -0
  31. data/lib/capybara/poltergeist/inspector.rb +46 -0
  32. data/lib/capybara/poltergeist/json.rb +25 -0
  33. data/lib/capybara/poltergeist/network_traffic.rb +7 -0
  34. data/lib/capybara/poltergeist/network_traffic/error.rb +19 -0
  35. data/lib/capybara/poltergeist/network_traffic/request.rb +27 -0
  36. data/lib/capybara/poltergeist/network_traffic/response.rb +40 -0
  37. data/lib/capybara/poltergeist/node.rb +177 -0
  38. data/lib/capybara/poltergeist/server.rb +36 -0
  39. data/lib/capybara/poltergeist/utility.rb +9 -0
  40. data/lib/capybara/poltergeist/version.rb +5 -0
  41. data/lib/capybara/poltergeist/web_socket_server.rb +107 -0
  42. data/lib/capybara/poltergeistFork.rb +27 -0
  43. metadata +268 -0
@@ -0,0 +1,36 @@
1
+ module Capybara::Poltergeist
2
+ class Server
3
+ attr_reader :socket, :fixed_port, :timeout
4
+
5
+ def initialize(fixed_port = nil, timeout = nil)
6
+ @fixed_port = fixed_port
7
+ @timeout = timeout
8
+ start
9
+ end
10
+
11
+ def port
12
+ @socket.port
13
+ end
14
+
15
+ def timeout=(sec)
16
+ @timeout = @socket.timeout = sec
17
+ end
18
+
19
+ def start
20
+ @socket = WebSocketServer.new(fixed_port, timeout)
21
+ end
22
+
23
+ def stop
24
+ @socket.close
25
+ end
26
+
27
+ def restart
28
+ stop
29
+ start
30
+ end
31
+
32
+ def send(command)
33
+ @socket.send(command.id, command.message) or raise DeadClient.new(command.message)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,9 @@
1
+ module Capybara
2
+ module Poltergeist
3
+ class << self
4
+ def windows?
5
+ RbConfig::CONFIG["host_os"] =~ /mingw|mswin|cygwin/
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Capybara
2
+ module Poltergeist
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,107 @@
1
+ require 'socket'
2
+ require 'websocket/driver'
3
+
4
+ module Capybara::Poltergeist
5
+ # This is a 'custom' Web Socket server that is designed to be synchronous. What
6
+ # this means is that it sends a message, and then waits for a response. It does
7
+ # not expect to receive a message at any other time than right after it has sent
8
+ # a message. So it is basically operating a request/response cycle (which is not
9
+ # how Web Sockets are usually used, but it's what we want here, as we want to
10
+ # send a message to PhantomJS and then wait for it to respond).
11
+ class WebSocketServer
12
+ # How much to try to read from the socket at once (it's kinda arbitrary because we
13
+ # just keep reading until we've received a full frame)
14
+ RECV_SIZE = 1024
15
+
16
+ # How many seconds to try to bind to the port for before failing
17
+ BIND_TIMEOUT = 5
18
+
19
+ HOST = '127.0.0.1'
20
+
21
+ attr_reader :port, :driver, :socket, :server
22
+ attr_accessor :timeout
23
+
24
+ def initialize(port = nil, timeout = nil)
25
+ @timeout = timeout
26
+ @server = start_server(port)
27
+ @receive_mutex = Mutex.new
28
+ end
29
+
30
+ def start_server(port)
31
+ time = Time.now
32
+
33
+ begin
34
+ TCPServer.open(HOST, port || 0).tap do |server|
35
+ @port = server.addr[1]
36
+ end
37
+ rescue Errno::EADDRINUSE
38
+ if (Time.now - time) < BIND_TIMEOUT
39
+ sleep(0.01)
40
+ retry
41
+ else
42
+ raise
43
+ end
44
+ end
45
+ end
46
+
47
+ def connected?
48
+ !socket.nil?
49
+ end
50
+
51
+ # Accept a client on the TCP server socket, then receive its initial HTTP request
52
+ # and use that to initialize a Web Socket.
53
+ def accept
54
+ @socket = server.accept
55
+ @messages = {}
56
+
57
+ @driver = ::WebSocket::Driver.server(self)
58
+ @driver.on(:connect) { |event| @driver.start }
59
+ @driver.on(:message) do |event|
60
+ command_id = JSON.load(event.data)['command_id']
61
+ @messages[command_id] = event.data
62
+ end
63
+ end
64
+
65
+ def write(data)
66
+ @socket.write(data)
67
+ end
68
+
69
+ # Block until the next message is available from the Web Socket.
70
+ # Raises Errno::EWOULDBLOCK if timeout is reached.
71
+ def receive(cmd_id)
72
+ start = Time.now
73
+
74
+ until @messages.has_key?(cmd_id)
75
+ raise Errno::EWOULDBLOCK if (Time.now - start) >= timeout
76
+ if @receive_mutex.try_lock
77
+ begin
78
+ IO.select([socket], [], [], timeout) or raise Errno::EWOULDBLOCK
79
+ data = socket.recv(RECV_SIZE)
80
+ break if data.empty?
81
+ driver.parse(data)
82
+ ensure
83
+ @receive_mutex.unlock
84
+ end
85
+ else
86
+ sleep(0.05)
87
+ end
88
+ end
89
+ @messages.delete(cmd_id)
90
+ end
91
+
92
+ # Send a message and block until there is a response
93
+ def send(cmd_id, message)
94
+ accept unless connected?
95
+ driver.text(message)
96
+ receive(cmd_id)
97
+ rescue Errno::EWOULDBLOCK
98
+ raise TimeoutError.new(message)
99
+ end
100
+
101
+ # Closing sockets separately as `close_read`, `close_write`
102
+ # causes IO mistakes on JRuby, using just `close` fixes that.
103
+ def close
104
+ [server, socket].compact.each(&:close)
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,27 @@
1
+ if RUBY_VERSION < "1.9.2"
2
+ raise "This version of Capybara/Poltergeist does not support Ruby versions " \
3
+ "less than 1.9.2."
4
+ end
5
+
6
+ require 'capybara'
7
+
8
+ module Capybara
9
+ module Poltergeist
10
+ require 'capybara/poltergeist/utility'
11
+ require 'capybara/poltergeist/driver'
12
+ require 'capybara/poltergeist/browser'
13
+ require 'capybara/poltergeist/node'
14
+ require 'capybara/poltergeist/server'
15
+ require 'capybara/poltergeist/web_socket_server'
16
+ require 'capybara/poltergeist/client'
17
+ require 'capybara/poltergeist/inspector'
18
+ require 'capybara/poltergeist/json'
19
+ require 'capybara/poltergeist/network_traffic'
20
+ require 'capybara/poltergeist/errors'
21
+ require 'capybara/poltergeist/cookie'
22
+ end
23
+ end
24
+
25
+ Capybara.register_driver :poltergeist do |app|
26
+ Capybara::Poltergeist::Driver.new(app)
27
+ end
metadata ADDED
@@ -0,0 +1,268 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: poltergeistFork
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - vianull
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capybara
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
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
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: cliver
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.3.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.3.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: launchy
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.4.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.4.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-core
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "!="
102
+ - !ruby/object:Gem::Version
103
+ version: 3.4.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "!="
109
+ - !ruby/object:Gem::Version
110
+ version: 3.4.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: sinatra
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '10.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '10.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: image_size
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1.0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: pdf-reader
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 1.3.3
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 1.3.3
167
+ - !ruby/object:Gem::Dependency
168
+ name: coffee-script
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '2.2'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '2.2'
181
+ - !ruby/object:Gem::Dependency
182
+ name: guard-coffeescript
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: 2.0.0
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: 2.0.0
195
+ description: Poltergeist is a driver for Capybara that allows you to run your tests
196
+ on a headless WebKit browser, provided by PhantomJS.
197
+ email:
198
+ - vianull@outlook.com
199
+ executables: []
200
+ extensions: []
201
+ extra_rdoc_files: []
202
+ files:
203
+ - LICENSE
204
+ - README.md
205
+ - lib/capybara/poltergeist/browser.rb
206
+ - lib/capybara/poltergeist/client.rb
207
+ - lib/capybara/poltergeist/client/agent.coffee
208
+ - lib/capybara/poltergeist/client/browser.coffee
209
+ - lib/capybara/poltergeist/client/cmd.coffee
210
+ - lib/capybara/poltergeist/client/compiled/agent.js
211
+ - lib/capybara/poltergeist/client/compiled/browser.js
212
+ - lib/capybara/poltergeist/client/compiled/cmd.js
213
+ - lib/capybara/poltergeist/client/compiled/connection.js
214
+ - lib/capybara/poltergeist/client/compiled/main.js
215
+ - lib/capybara/poltergeist/client/compiled/node.js
216
+ - lib/capybara/poltergeist/client/compiled/web_page.js
217
+ - lib/capybara/poltergeist/client/connection.coffee
218
+ - lib/capybara/poltergeist/client/main.coffee
219
+ - lib/capybara/poltergeist/client/node.coffee
220
+ - lib/capybara/poltergeist/client/pre/agent.js
221
+ - lib/capybara/poltergeist/client/pre/browser.js
222
+ - lib/capybara/poltergeist/client/pre/cmd.js
223
+ - lib/capybara/poltergeist/client/pre/connection.js
224
+ - lib/capybara/poltergeist/client/pre/main.js
225
+ - lib/capybara/poltergeist/client/pre/node.js
226
+ - lib/capybara/poltergeist/client/pre/web_page.js
227
+ - lib/capybara/poltergeist/client/web_page.coffee
228
+ - lib/capybara/poltergeist/command.rb
229
+ - lib/capybara/poltergeist/cookie.rb
230
+ - lib/capybara/poltergeist/driver.rb
231
+ - lib/capybara/poltergeist/errors.rb
232
+ - lib/capybara/poltergeist/inspector.rb
233
+ - lib/capybara/poltergeist/json.rb
234
+ - lib/capybara/poltergeist/network_traffic.rb
235
+ - lib/capybara/poltergeist/network_traffic/error.rb
236
+ - lib/capybara/poltergeist/network_traffic/request.rb
237
+ - lib/capybara/poltergeist/network_traffic/response.rb
238
+ - lib/capybara/poltergeist/node.rb
239
+ - lib/capybara/poltergeist/server.rb
240
+ - lib/capybara/poltergeist/utility.rb
241
+ - lib/capybara/poltergeist/version.rb
242
+ - lib/capybara/poltergeist/web_socket_server.rb
243
+ - lib/capybara/poltergeistFork.rb
244
+ homepage:
245
+ licenses:
246
+ - MIT
247
+ metadata: {}
248
+ post_install_message:
249
+ rdoc_options: []
250
+ require_paths:
251
+ - lib
252
+ required_ruby_version: !ruby/object:Gem::Requirement
253
+ requirements:
254
+ - - ">="
255
+ - !ruby/object:Gem::Version
256
+ version: 1.9.3
257
+ required_rubygems_version: !ruby/object:Gem::Requirement
258
+ requirements:
259
+ - - ">="
260
+ - !ruby/object:Gem::Version
261
+ version: '0'
262
+ requirements: []
263
+ rubyforge_project:
264
+ rubygems_version: 2.4.3
265
+ signing_key:
266
+ specification_version: 4
267
+ summary: PhantomJS driver for Capybara,fork from poltergeist
268
+ test_files: []