capybara-chrome_dev_tools 0.1.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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Changelog.md +0 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/License +18 -0
- data/Rakefile +6 -0
- data/Readme.md +45 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/capybara-chrome_dev_tools.gemspec +36 -0
- data/lib/capybara/chrome_dev_tools.rb +27 -0
- data/lib/capybara/chrome_dev_tools/driver_extensions.rb +76 -0
- data/lib/capybara/chrome_dev_tools/dsl.rb +9 -0
- data/lib/capybara/chrome_dev_tools/version.rb +7 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b0d10204e92fbd7b34ca84ec1a36c9bd2c258b5d
|
4
|
+
data.tar.gz: a3a5f57d5f82d507d7c8d11ae1830ade58aec9ef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 05dbdb5a1312649714ac33c3f4ad8581cfa13ab564380113ac57abaed6aecac9ae8af44784d68a1591dffbe5f8fce9e268f26651558dd97187769c4579769bae
|
7
|
+
data.tar.gz: 90ef9227ab6c4a5e8f77feb5f967d7109b82ea0f0147d6a1b67c870c36420ff3b8ac0f5f7041e3b56e3073cea85cfb4f07c34d70713123d3709da6962e8a73fb
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Changelog.md
ADDED
File without changes
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Tyler Rick
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/License
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2018 Tyler Rick
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
4
|
+
associated documentation files (the "Software"), to deal in the Software without restriction,
|
5
|
+
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
6
|
+
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
7
|
+
furnished to do so, subject to the following conditions:
|
8
|
+
|
9
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial
|
10
|
+
portions of the Software.
|
11
|
+
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
13
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
14
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
15
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
16
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
17
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
18
|
+
SOFTWARE.
|
data/Rakefile
ADDED
data/Readme.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Capybara::ChromeDevTools
|
2
|
+
|
3
|
+
Integrates [chrome_remote](https://github.com/cavalle/chrome_remote) (a Chrome DevTools Protocol
|
4
|
+
client) with Capybara, letting you access Chrome DevTools via `driver.dev_tools`.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Install crmux by running, for example:
|
9
|
+
```
|
10
|
+
npm install crmux -g
|
11
|
+
```
|
12
|
+
or
|
13
|
+
```
|
14
|
+
yarn add crmux
|
15
|
+
```
|
16
|
+
|
17
|
+
Test that you can run it with:
|
18
|
+
```
|
19
|
+
npx crmux --help
|
20
|
+
```
|
21
|
+
|
22
|
+
Add this line to your application's Gemfile:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
gem 'capybara-chrome_dev_tools'
|
26
|
+
```
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
Access a ChromeRemote instance with `dev_tools`.
|
31
|
+
|
32
|
+
See [chrome_remote](https://github.com/cavalle/chrome_remote) for API documentation.
|
33
|
+
|
34
|
+
Example:
|
35
|
+
```ruby
|
36
|
+
dev_tools.send_cmd "Page.enable"
|
37
|
+
```
|
38
|
+
|
39
|
+
## See also
|
40
|
+
|
41
|
+
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.
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/TylerRick/capybara-chrome_dev_tools.
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "capybara/chrome_dev_tools"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "capybara/chrome_dev_tools/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "capybara-chrome_dev_tools"
|
7
|
+
spec.version = Capybara::ChromeDevTools.version
|
8
|
+
spec.authors = ["Tyler Rick"]
|
9
|
+
spec.email = ["tyler@tylerrick.com"]
|
10
|
+
spec.license = "MIT"
|
11
|
+
|
12
|
+
spec.summary = %q{Integrates [chrome_remote](https://github.com/cavalle/chrome_remote) (a Chrome DevTools Protocol
|
13
|
+
client) with Capybara, letting you access Chrome DevTools via `driver.dev_tools`.}
|
14
|
+
#spec.description = %q{}
|
15
|
+
spec.homepage = "https://github.com/TylerRick/capybara-chrome_dev_tools"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
spec.metadata["changelog_uri"] = "#{spec.metadata["source_code_uri"]}/blob/master/Changelog.md"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.required_ruby_version = ">= 2.3.0"
|
31
|
+
spec.add_dependency "chrome_remote"
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "capybara/chrome_dev_tools/version"
|
2
|
+
|
3
|
+
module Capybara::ChromeDevTools
|
4
|
+
autoload :DriverExtensions, 'capybara/chrome_dev_tools/driver_extensions'
|
5
|
+
autoload :DSL, 'capybara/chrome_dev_tools/dsl'
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :preferred_port
|
9
|
+
end
|
10
|
+
self.preferred_port = 9222
|
11
|
+
end
|
12
|
+
|
13
|
+
Capybara::Selenium::Driver.class_eval do
|
14
|
+
prepend Capybara::ChromeDevTools::DriverExtensions
|
15
|
+
end
|
16
|
+
|
17
|
+
Capybara::Session.class_eval do
|
18
|
+
##
|
19
|
+
# Returns a client for the browser's dev tools protocol. Not supported by all drivers.
|
20
|
+
def dev_tools
|
21
|
+
driver.dev_tools
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Capybara::DSL
|
26
|
+
include Capybara::ChromeDevTools::DSL
|
27
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'chrome_remote'
|
2
|
+
|
3
|
+
module Capybara::ChromeDevTools
|
4
|
+
module DriverExtensions
|
5
|
+
attr_accessor :chrome_debugging_port
|
6
|
+
attr_accessor :crmux_listen_port
|
7
|
+
|
8
|
+
def initialize(app, opts)
|
9
|
+
puts "#{self.class}#initialize"
|
10
|
+
|
11
|
+
if opts[:browser] == :chrome
|
12
|
+
start_crmux!(opts)
|
13
|
+
end
|
14
|
+
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def find_free_port(port = 0)
|
19
|
+
begin
|
20
|
+
server = TCPServer.new('127.0.0.1', port)
|
21
|
+
rescue Errno::EADDRINUSE
|
22
|
+
if port == 0
|
23
|
+
raise
|
24
|
+
else
|
25
|
+
# Lets you pass a preferred port to try first before falling back to 0
|
26
|
+
port = 0
|
27
|
+
retry
|
28
|
+
end
|
29
|
+
end
|
30
|
+
server.addr[1].tap do |port|
|
31
|
+
server.close
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Starts crmux and adds debuggerAddress to opts that points to crmux listen address.
|
36
|
+
def start_crmux!(opts)
|
37
|
+
self.chrome_debugging_port = find_free_port(Capybara::ChromeDevTools.preferred_port)
|
38
|
+
self.crmux_listen_port = find_free_port(chrome_debugging_port + 1)
|
39
|
+
opts[:options].args << "--remote-debugging-port=#{chrome_debugging_port}"
|
40
|
+
#opts[:options].add_preference 'debuggerAddress', "127.0.0.1:#{crmux_listen_port}"
|
41
|
+
|
42
|
+
@debug_crmux = true
|
43
|
+
command = "npx crmux #{'-d' if @debug_crmux} \
|
44
|
+
--port=#{chrome_debugging_port} \
|
45
|
+
--listen=#{crmux_listen_port}"
|
46
|
+
#puts %(command: #{command})
|
47
|
+
if @debug_crmux
|
48
|
+
spawn_opts = {[:out, :err] => 'log/crmux.log'}
|
49
|
+
else
|
50
|
+
spawn_opts = {}
|
51
|
+
end
|
52
|
+
@crmux_pid = spawn(command, spawn_opts)
|
53
|
+
puts %(Started crmux [pid #{@crmux_pid}], listening at http://localhost:#{crmux_listen_port}, connected to localhost:#{chrome_debugging_port})
|
54
|
+
# You can also get the part later with: page.driver.browser.capabilities["goog:chromeOptions"]["debuggerAddress"]
|
55
|
+
sleep 0.1
|
56
|
+
|
57
|
+
at_exit do
|
58
|
+
puts "Killing crmux process #{@crmux_pid}..."
|
59
|
+
Process.kill 'TERM', @crmux_pid
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def browser
|
64
|
+
super.tap do |browser|
|
65
|
+
dev_tools
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def dev_tools
|
70
|
+
@dev_tools ||= (
|
71
|
+
#puts "Connecting to #{crmux_listen_port}..."
|
72
|
+
ChromeRemote.client host: 'localhost', port: crmux_listen_port
|
73
|
+
)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capybara-chrome_dev_tools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tyler Rick
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: chrome_remote
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.17'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.17'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- tyler@tylerrick.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Changelog.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE
|
82
|
+
- License
|
83
|
+
- Rakefile
|
84
|
+
- Readme.md
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- capybara-chrome_dev_tools.gemspec
|
88
|
+
- lib/capybara/chrome_dev_tools.rb
|
89
|
+
- lib/capybara/chrome_dev_tools/driver_extensions.rb
|
90
|
+
- lib/capybara/chrome_dev_tools/dsl.rb
|
91
|
+
- lib/capybara/chrome_dev_tools/version.rb
|
92
|
+
homepage: https://github.com/TylerRick/capybara-chrome_dev_tools
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata:
|
96
|
+
homepage_uri: https://github.com/TylerRick/capybara-chrome_dev_tools
|
97
|
+
source_code_uri: https://github.com/TylerRick/capybara-chrome_dev_tools
|
98
|
+
changelog_uri: https://github.com/TylerRick/capybara-chrome_dev_tools/blob/master/Changelog.md
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: 2.3.0
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.6.14.3
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Integrates [chrome_remote](https://github.com/cavalle/chrome_remote) (a Chrome
|
119
|
+
DevTools Protocol client) with Capybara, letting you access Chrome DevTools via
|
120
|
+
`driver.dev_tools`.
|
121
|
+
test_files: []
|