cuprite 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +103 -67
- data/lib/capybara/cuprite.rb +8 -21
- data/lib/capybara/cuprite/browser.rb +66 -224
- data/lib/capybara/cuprite/driver.rb +87 -44
- data/lib/capybara/cuprite/errors.rb +1 -64
- data/lib/capybara/cuprite/{browser/javascripts → javascripts}/index.js +26 -20
- data/lib/capybara/cuprite/node.rb +37 -31
- data/lib/capybara/cuprite/page.rb +166 -0
- data/lib/capybara/cuprite/version.rb +1 -1
- metadata +8 -42
- data/lib/capybara/cuprite/browser/client.rb +0 -74
- data/lib/capybara/cuprite/browser/dom.rb +0 -50
- data/lib/capybara/cuprite/browser/frame.rb +0 -115
- data/lib/capybara/cuprite/browser/input.json +0 -1341
- data/lib/capybara/cuprite/browser/input.rb +0 -200
- data/lib/capybara/cuprite/browser/net.rb +0 -90
- data/lib/capybara/cuprite/browser/page.rb +0 -378
- data/lib/capybara/cuprite/browser/process.rb +0 -223
- data/lib/capybara/cuprite/browser/runtime.rb +0 -182
- data/lib/capybara/cuprite/browser/targets.rb +0 -129
- data/lib/capybara/cuprite/browser/web_socket.rb +0 -69
- data/lib/capybara/cuprite/network/error.rb +0 -25
- data/lib/capybara/cuprite/network/request.rb +0 -33
- data/lib/capybara/cuprite/network/response.rb +0 -44
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "json"
|
4
|
-
require "socket"
|
5
|
-
require "websocket/driver"
|
6
|
-
|
7
|
-
module Capybara::Cuprite
|
8
|
-
class Browser
|
9
|
-
class WebSocket
|
10
|
-
attr_reader :url, :messages
|
11
|
-
|
12
|
-
def initialize(url, logger)
|
13
|
-
@url = url
|
14
|
-
@logger = logger
|
15
|
-
uri = URI.parse(@url)
|
16
|
-
@sock = TCPSocket.new(uri.host, uri.port)
|
17
|
-
@driver = ::WebSocket::Driver.client(self)
|
18
|
-
@messages = Queue.new
|
19
|
-
|
20
|
-
@driver.on(:open, &method(:on_open))
|
21
|
-
@driver.on(:message, &method(:on_message))
|
22
|
-
@driver.on(:close, &method(:on_close))
|
23
|
-
|
24
|
-
@thread = Thread.new do
|
25
|
-
begin
|
26
|
-
while data = @sock.readpartial(512)
|
27
|
-
@driver.parse(data)
|
28
|
-
end
|
29
|
-
rescue EOFError, Errno::ECONNRESET
|
30
|
-
@messages.close
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
@thread.priority = 1
|
35
|
-
|
36
|
-
@driver.start
|
37
|
-
end
|
38
|
-
|
39
|
-
def on_open(_event)
|
40
|
-
sleep 0.01 # https://github.com/faye/websocket-driver-ruby/issues/46
|
41
|
-
end
|
42
|
-
|
43
|
-
def on_message(event)
|
44
|
-
data = JSON.parse(event.data)
|
45
|
-
@messages.push(data)
|
46
|
-
@logger&.puts(" <<< #{event.data}\n")
|
47
|
-
end
|
48
|
-
|
49
|
-
def on_close(_event)
|
50
|
-
@messages.close
|
51
|
-
@thread.kill
|
52
|
-
end
|
53
|
-
|
54
|
-
def send_message(data)
|
55
|
-
json = data.to_json
|
56
|
-
@driver.text(json)
|
57
|
-
@logger&.puts("\n\n>>> #{json}")
|
58
|
-
end
|
59
|
-
|
60
|
-
def write(data)
|
61
|
-
@sock.write(data)
|
62
|
-
end
|
63
|
-
|
64
|
-
def close
|
65
|
-
@driver.close
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Capybara::Cuprite::Network
|
4
|
-
class Error
|
5
|
-
def initialize(data)
|
6
|
-
@data = data
|
7
|
-
end
|
8
|
-
|
9
|
-
def id
|
10
|
-
@data["networkRequestId"]
|
11
|
-
end
|
12
|
-
|
13
|
-
def url
|
14
|
-
@data["url"]
|
15
|
-
end
|
16
|
-
|
17
|
-
def description
|
18
|
-
@data["text"]
|
19
|
-
end
|
20
|
-
|
21
|
-
def time
|
22
|
-
@time ||= Time.strptime(@data["timestamp"].to_s, "%s")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "time"
|
4
|
-
|
5
|
-
module Capybara::Cuprite::Network
|
6
|
-
class Request
|
7
|
-
attr_accessor :response, :error
|
8
|
-
|
9
|
-
def initialize(data)
|
10
|
-
@data = data
|
11
|
-
end
|
12
|
-
|
13
|
-
def id
|
14
|
-
@data["id"]
|
15
|
-
end
|
16
|
-
|
17
|
-
def url
|
18
|
-
@data["url"]
|
19
|
-
end
|
20
|
-
|
21
|
-
def method
|
22
|
-
@data["method"]
|
23
|
-
end
|
24
|
-
|
25
|
-
def headers
|
26
|
-
@data["headers"]
|
27
|
-
end
|
28
|
-
|
29
|
-
def time
|
30
|
-
@time ||= Time.strptime(@data["time"].to_s, "%s")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Capybara::Cuprite::Network
|
4
|
-
class Response
|
5
|
-
attr_accessor :body_size
|
6
|
-
|
7
|
-
def initialize(data)
|
8
|
-
@data = data
|
9
|
-
end
|
10
|
-
|
11
|
-
def id
|
12
|
-
@data["id"]
|
13
|
-
end
|
14
|
-
|
15
|
-
def url
|
16
|
-
@data["url"]
|
17
|
-
end
|
18
|
-
|
19
|
-
def status
|
20
|
-
@data["status"]
|
21
|
-
end
|
22
|
-
|
23
|
-
def status_text
|
24
|
-
@data["statusText"]
|
25
|
-
end
|
26
|
-
|
27
|
-
def headers
|
28
|
-
@data["headers"]
|
29
|
-
end
|
30
|
-
|
31
|
-
def headers_size
|
32
|
-
@data["encodedDataLength"]
|
33
|
-
end
|
34
|
-
|
35
|
-
# FIXME: didn't check if we have it on redirect response
|
36
|
-
def redirect_url
|
37
|
-
@data["redirectURL"]
|
38
|
-
end
|
39
|
-
|
40
|
-
def content_type
|
41
|
-
@content_type ||= @data.dig("headers", "contentType").sub(/;.*\z/, "")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|