capybara-chrome_dev_tools 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0d10204e92fbd7b34ca84ec1a36c9bd2c258b5d
4
- data.tar.gz: a3a5f57d5f82d507d7c8d11ae1830ade58aec9ef
3
+ metadata.gz: b2a0b532302f3f1b2e4c6c654893ef551c801d45
4
+ data.tar.gz: d3dbd664cef2aaf7970ac0c10a31dc4bdec1d147
5
5
  SHA512:
6
- metadata.gz: 05dbdb5a1312649714ac33c3f4ad8581cfa13ab564380113ac57abaed6aecac9ae8af44784d68a1591dffbe5f8fce9e268f26651558dd97187769c4579769bae
7
- data.tar.gz: 90ef9227ab6c4a5e8f77feb5f967d7109b82ea0f0147d6a1b67c870c36420ff3b8ac0f5f7041e3b56e3073cea85cfb4f07c34d70713123d3709da6962e8a73fb
6
+ metadata.gz: a7886d9a272805a7c06a700deaa5db7fe05f591f81adb94af2205f8ed197fee9f8c9c49f8e5f1bcb91b04a237a32b90484e572a9b21717d4fb9afb3ec2254039
7
+ data.tar.gz: 55c00a25215425d2bcbc483f5b015c0a4768739d82cc9b49f06f1261b7d97ce6fc5281d8d113014eed12ebf97f6e3a0d07f2b88ffb022c827c8d0bf98103a2b9
data/Readme.md CHANGED
@@ -3,9 +3,24 @@
3
3
  Integrates [chrome_remote](https://github.com/cavalle/chrome_remote) (a Chrome DevTools Protocol
4
4
  client) with Capybara, letting you access Chrome DevTools via `driver.dev_tools`.
5
5
 
6
+ ## What it does for you
7
+
8
+ - Finds a free port and sets Chrome's --remote-debugging-port to this known port
9
+ - Starts [`crmux`](https://github.com/sidorares/crmux) so that you can make additional connections
10
+ to the Chrome DevTools/debugging port even while `chromedriver` continues to connect to the
11
+ `--remote-debugging-port` (Chrome normally only allows one debugging session to be connected to a
12
+ tab)
13
+ - Lets you inspect the browser window your tests are running in — even if they are running in a
14
+ headless Chrome browser!
15
+ - Exposes a `dev_tools` method that provides access to a `ChromeRemote` instance (see
16
+ [capybara-chrome_response_headers](https://github.com/TylerRick/capybara-chrome_response_headers),
17
+ for one possible use for that)
18
+
19
+ Inspired by: https://stackoverflow.com/a/50876153/47185
20
+
6
21
  ## Installation
7
22
 
8
- Install crmux by running, for example:
23
+ Install [`crmux`](https://github.com/sidorares/crmux) by running, for example:
9
24
  ```
10
25
  npm install crmux -g
11
26
  ```
@@ -27,6 +42,33 @@ gem 'capybara-chrome_dev_tools'
27
42
 
28
43
  ## Usage
29
44
 
45
+ Enable this extension like so:
46
+ ```
47
+ Capybara::ChromeDevTools.enabled = true
48
+ ```
49
+
50
+ ... before you do any action with Capybara that triggers it to use the Chrome driver/browser.
51
+
52
+ ### Accessing DevTools from another Chrome window
53
+
54
+ Add some code to your test to make it _pause_ at the point where you want to inspect the state of
55
+ the browser window. Otherwise, when the test finishes, it will close the window that you are
56
+ inspecting and disconnect the DevTools frontend that you were using to view it.
57
+
58
+ Look for the output which teels you which port it's listening to:
59
+
60
+ ```
61
+ Started crmux [pid 56630], listening at http://localhost:35720, connected to localhost:35719
62
+ ```
63
+
64
+ Now you can go to http://localhost:35720, choose which window to inspect, and inspect the Chrome
65
+ window that your tests are running in — all from this other Chrome browser instance!
66
+
67
+ You can also get the listen port from `driver.crmux_listen_port` if you want to
68
+ automate things.
69
+
70
+ ### Accessing DevTools from Ruby
71
+
30
72
  Access a ChromeRemote instance with `dev_tools`.
31
73
 
32
74
  See [chrome_remote](https://github.com/cavalle/chrome_remote) for API documentation.
@@ -36,6 +78,16 @@ Example:
36
78
  dev_tools.send_cmd "Page.enable"
37
79
  ```
38
80
 
81
+ ## Status
82
+
83
+ This project should be considered a proof of concept.
84
+
85
+ It generally works, but isn't exceptionally resilient or stable.
86
+
87
+ Sometimes you may get intermittent errors from `chrome_remote` or the WebSocket connection. There
88
+ should probably be some handling of these errors (or better yet, figure out what's causing the
89
+ errors).
90
+
39
91
  ## See also
40
92
 
41
93
  To get access to HTTP response status code, response headers, etc. from your tests, check out https://github.com/TylerRick/capybara-chrome_response_headers, which uses this gem.
@@ -5,9 +5,13 @@ module Capybara::ChromeDevTools
5
5
  autoload :DSL, 'capybara/chrome_dev_tools/dsl'
6
6
 
7
7
  class << self
8
+ attr_accessor :enabled
8
9
  attr_accessor :preferred_port
10
+ attr_accessor :verbose
9
11
  end
12
+ self.enabled = false
10
13
  self.preferred_port = 9222
14
+ self.verbose = 1
11
15
  end
12
16
 
13
17
  Capybara::Selenium::Driver.class_eval do
@@ -6,9 +6,9 @@ module Capybara::ChromeDevTools
6
6
  attr_accessor :crmux_listen_port
7
7
 
8
8
  def initialize(app, opts)
9
- puts "#{self.class}#initialize"
9
+ #puts "#{self.class}#initialize"
10
10
 
11
- if opts[:browser] == :chrome
11
+ if opts[:browser] == :chrome and Capybara::ChromeDevTools.enabled
12
12
  start_crmux!(opts)
13
13
  end
14
14
 
@@ -43,7 +43,7 @@ module Capybara::ChromeDevTools
43
43
  command = "npx crmux #{'-d' if @debug_crmux} \
44
44
  --port=#{chrome_debugging_port} \
45
45
  --listen=#{crmux_listen_port}"
46
- #puts %(command: #{command})
46
+ puts %(command: #{command}) if Capybara::ChromeDevTools.verbose >= 3
47
47
  if @debug_crmux
48
48
  spawn_opts = {[:out, :err] => 'log/crmux.log'}
49
49
  else
@@ -55,20 +55,20 @@ module Capybara::ChromeDevTools
55
55
  sleep 0.1
56
56
 
57
57
  at_exit do
58
- puts "Killing crmux process #{@crmux_pid}..."
58
+ puts "Killing crmux process #{@crmux_pid}..." if Capybara::ChromeDevTools.verbose >= 1
59
59
  Process.kill 'TERM', @crmux_pid
60
60
  end
61
61
  end
62
62
 
63
63
  def browser
64
64
  super.tap do |browser|
65
- dev_tools
65
+ dev_tools if Capybara::ChromeDevTools.enabled
66
66
  end
67
67
  end
68
68
 
69
69
  def dev_tools
70
70
  @dev_tools ||= (
71
- #puts "Connecting to #{crmux_listen_port}..."
71
+ puts "Connecting to #{crmux_listen_port}..." if Capybara::ChromeDevTools.verbose >= 2
72
72
  ChromeRemote.client host: 'localhost', port: crmux_listen_port
73
73
  )
74
74
  end
@@ -1,7 +1,7 @@
1
1
  module Capybara
2
2
  module ChromeDevTools
3
3
  def self.version
4
- "0.1.0"
4
+ "0.2.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-chrome_dev_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Rick