capybara-chrome_response_headers 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37f3924dc1a7c659127afe9cf709b71eb14f2d43
|
4
|
+
data.tar.gz: 04d15916559bb40e738c5096c92f6d0492e6020f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63ea74a00eee193693886351c3742b564fef85d950276f258eaaa7cbb33da7d13192dd1c054f4bf97203052650f68bfab9b3081201ec51dc0ac3ef2255784e90
|
7
|
+
data.tar.gz: f28e54e082305b093909b14a99c7d02bf017d076877c232c7148aefcdb06f77d8c83dbbc8e33b2f0724bd6ce933fba05ea1edcbcbb9ead23276816d097ec8f00
|
data/Readme.md
CHANGED
@@ -43,10 +43,45 @@ Example:
|
|
43
43
|
end
|
44
44
|
```
|
45
45
|
|
46
|
+
## Tracing
|
47
|
+
|
48
|
+
To have it show a trace of all requests and/or responses that are made from the web pages you are interacting with, enable these settings, respectively:
|
49
|
+
|
50
|
+
```
|
51
|
+
Capybara::ChromeResponseHeaders.trace_requests = true
|
52
|
+
Capybara::ChromeResponseHeaders.trace_responses = true
|
53
|
+
```
|
54
|
+
|
55
|
+
The output for responses is something like this:
|
56
|
+
```
|
57
|
+
Response for http://127.0.0.1:40359/users/sign_in: 200 OK
|
58
|
+
Response for http://127.0.0.1:40359/admin: 200 OK
|
59
|
+
```
|
60
|
+
|
61
|
+
By default, it tries to filter out requests for assets. (`Capybara::ChromeResponseHeaders.ignore_urls` is set to `/\.(js|css|png|gif|jpg)$/`.)
|
62
|
+
|
63
|
+
You can turn off this filtering by setting `Capybara::ChromeResponseHeaders.ignore_urls = nil`, or
|
64
|
+
set it to a different Regexp pattern to ignore.
|
65
|
+
|
66
|
+
If you want other behavior to happen on each request or response, you should be able to add it via `dev_tools` (a [ChromeRemote]((https://github.com/cavalle/chrome_remote) instance):
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
dev_tools.on "Network.requestWillBeSent" do |arg|
|
70
|
+
request = OpenStruct.new(arg["request"])
|
71
|
+
puts "Requesting #{request.url}"
|
72
|
+
end
|
73
|
+
|
74
|
+
dev_tools.on "Network.responseReceived" do |arg|
|
75
|
+
response = OpenStruct.new(arg["response"])
|
76
|
+
puts %(Response for #{response.url}"
|
77
|
+
end
|
78
|
+
```
|
79
|
+
|
46
80
|
## Why?
|
47
81
|
|
48
|
-
Because it
|
49
|
-
ability
|
82
|
+
Because it can be useful to be able to check the HTTP status code in tests. Many people have wanted
|
83
|
+
that ability. And the WebDriver maintainers have no intention of adding this feature. See, for
|
84
|
+
example:
|
50
85
|
|
51
86
|
- https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/141
|
52
87
|
- https://github.com/SeleniumHQ/selenium/issues/4976
|
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.require_paths = ["lib"]
|
28
28
|
|
29
29
|
spec.required_ruby_version = ">= 2.3.0"
|
30
|
-
spec.add_dependency "capybara-chrome_dev_tools", [">= 0.
|
30
|
+
spec.add_dependency "capybara-chrome_dev_tools", [">= 0.2"]
|
31
31
|
|
32
32
|
spec.add_development_dependency "bundler", "~> 1.17"
|
33
33
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -6,9 +6,13 @@ module Capybara::ChromeResponseHeaders
|
|
6
6
|
|
7
7
|
class << self
|
8
8
|
attr_accessor :verbose
|
9
|
+
attr_accessor :trace_requests
|
10
|
+
attr_accessor :trace_responses
|
9
11
|
attr_accessor :ignore_urls
|
10
12
|
end
|
11
|
-
self.verbose =
|
13
|
+
self.verbose = 0
|
14
|
+
self.trace_requests = false
|
15
|
+
self.trace_responses = false
|
12
16
|
# The default is to try to ignore asset files so that hopefully what's left is just HTML/API
|
13
17
|
# requests.
|
14
18
|
self.ignore_urls = /\.(js|css|png|gif|jpg)$/
|
@@ -14,7 +14,9 @@ module Capybara::ChromeResponseHeaders
|
|
14
14
|
|
15
15
|
def browser
|
16
16
|
super.tap do |browser|
|
17
|
-
|
17
|
+
if Capybara::ChromeDevTools.enabled and !@listening_to_network_traffic
|
18
|
+
listen_to_network_traffic
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
@@ -28,7 +30,7 @@ module Capybara::ChromeResponseHeaders
|
|
28
30
|
next if Capybara::ChromeResponseHeaders.ignore_urls && request.url.match(Capybara::ChromeResponseHeaders.ignore_urls)
|
29
31
|
|
30
32
|
@request_for_url[request.url] = request
|
31
|
-
puts "Requesting #{request.url}" if Capybara::ChromeResponseHeaders.
|
33
|
+
puts "Requesting #{request.url}" if Capybara::ChromeResponseHeaders.trace_requests
|
32
34
|
end
|
33
35
|
|
34
36
|
chrome.on "Network.responseReceived" do |arg|
|
@@ -37,7 +39,7 @@ module Capybara::ChromeResponseHeaders
|
|
37
39
|
|
38
40
|
# TODO: Use/return a Rack::Response like Rack::Test does
|
39
41
|
@response_for_url[response.url] = response
|
40
|
-
puts %(Response for #{response.url}: #{response.status} #{response.statusText}) if Capybara::ChromeResponseHeaders.
|
42
|
+
puts %(Response for #{response.url}: #{response.status} #{response.statusText}) if Capybara::ChromeResponseHeaders.trace_responses
|
41
43
|
end
|
42
44
|
|
43
45
|
@listener_thread = Thread.new do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-chrome_response_headers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Rick
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|