venetian 0.2.3 → 0.3.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 +4 -4
- data/README.md +35 -2
- data/exe/playwright +1 -1
- data/lib/tasks/venetian.rake +1 -1
- data/lib/venetian/browser_installer.rb +42 -11
- data/lib/venetian/browser_runner_extensions.rb +9 -2
- data/lib/venetian/core.rb +25 -0
- data/lib/venetian/executable.rb +27 -0
- data/lib/venetian/gemspec.rb +2 -0
- data/lib/venetian/playwright.rb +14 -0
- data/lib/venetian/playwright_create_extensions.rb +4 -1
- data/lib/venetian/system_test_case_extension.rb +3 -1
- data/lib/venetian/upstream.rb +1 -1
- data/lib/venetian/version.rb +1 -1
- data/lib/venetian.rb +4 -19
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0c599b422e667a871ef1b770d925eba77b670865bc3e93d453467f8868158a96
|
|
4
|
+
data.tar.gz: 10c75b357f976409bc73a3e7cb478e00f5f5bb34e2fdbcb02917ca88e96599e7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 78a685bc7a929fd1305905e727912787162f85f88d05983e4c1649d06a8a3055e37b9ba6bb979ca5ef3d15be2619b1ff93e46394849154d079081c5b7a10adfb
|
|
7
|
+
data.tar.gz: 26e00d4ce95a2f03f5f816272788d917d092d78aae6de9423acb488021d74e9e9cfd19323e85d6e1c3644a23269de12b2357f9d935d39f0fc238f28eea17ecab
|
data/README.md
CHANGED
|
@@ -38,9 +38,37 @@ Capybara.register_driver :playwright do |app|
|
|
|
38
38
|
end
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
### Using `playwright-ruby-client` without Capybara
|
|
42
|
+
|
|
43
|
+
Require the Capybara-free entry point instead, either in your Gemfile if you use `Bundler.require`:
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
gem "venetian", require: "venetian/playwright"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Or directly:
|
|
50
|
+
|
|
51
|
+
```ruby
|
|
52
|
+
require "venetian/playwright"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Then use `Venetian.start` in place of `Playwright.create`. It takes the same arguments, with the bundled executable as the default
|
|
56
|
+
`:playwright_cli_executable_path`. Browsers aren't installed automatically here, so install them first, either with
|
|
57
|
+
the [Rake task](#installing-browsers-manually) or `Venetian::BrowserInstaller.install`:
|
|
58
|
+
|
|
59
|
+
```ruby
|
|
60
|
+
Venetian::BrowserInstaller.install(:chromium)
|
|
61
|
+
|
|
62
|
+
Venetian.start do |playwright|
|
|
63
|
+
playwright.chromium.launch do |browser|
|
|
64
|
+
# ...
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
```
|
|
68
|
+
|
|
41
69
|
### Automatic browser and dependency installation
|
|
42
70
|
|
|
43
|
-
|
|
71
|
+
With Capybara or Rails system tests, the gem will automatically install a browser and dependencies for you before attempting to use it.
|
|
44
72
|
Browsers are installed to `$XDG_CACHE_HOME/ms-playwright` on Linux, `~/Library/Caches/ms-playwright` on macOS,
|
|
45
73
|
and `%LOCALAPPDATA%\ms-playwright` on Windows. In CI, you will want to
|
|
46
74
|
[cache this directory](https://docs.github.com/en/actions/reference/workflows-and-actions/dependency-caching)
|
|
@@ -57,10 +85,15 @@ When parallelizing tests, there's also the issue of multiple processes all tryin
|
|
|
57
85
|
if you use Rails system tests with `ActionDispatch::SystemTestCase`,
|
|
58
86
|
this is handled automatically by installing all required browsers before disabling auto-installation and then forking.
|
|
59
87
|
|
|
88
|
+
Browsers aren't installed automatically if you pass your own `:playwright_cli_executable_path`, or connect to a server with
|
|
89
|
+
`:playwright_server_endpoint_url` or `:browser_server_endpoint_url`, since the bundled executable won't be the one running them.
|
|
90
|
+
You can also turn installation off with `Venetian.auto_install_browsers = false`, or just dependency installation with
|
|
91
|
+
`Venetian.auto_install_dependencies = false`.
|
|
92
|
+
|
|
60
93
|
### Installing browsers manually
|
|
61
94
|
|
|
62
95
|
If you can't rely on automatic installation, you can use the included Rake task to install browsers.
|
|
63
|
-
With Rails this is included automatically when
|
|
96
|
+
With Rails this is included automatically when `venetian` is required (but not `venetian/playwright`).
|
|
64
97
|
|
|
65
98
|
```bash
|
|
66
99
|
$ RAILS_ENV=test rails venetian:install
|
data/exe/playwright
CHANGED
data/lib/tasks/venetian.rake
CHANGED
|
@@ -5,7 +5,7 @@ namespace :venetian do
|
|
|
5
5
|
Install Playwright browsers. Pass a name to install a specific browser (e.g. venetian:install[chromium]), else installs default browsers.
|
|
6
6
|
USAGE
|
|
7
7
|
task :install, [:browser] do |_task, args|
|
|
8
|
-
require "venetian"
|
|
8
|
+
require "venetian/core"
|
|
9
9
|
Venetian::BrowserInstaller.install(args[:browser])
|
|
10
10
|
end
|
|
11
11
|
end
|
|
@@ -8,12 +8,22 @@ module Venetian
|
|
|
8
8
|
class << self
|
|
9
9
|
private
|
|
10
10
|
|
|
11
|
-
def install_dependencies?
|
|
12
|
-
|
|
11
|
+
def install_dependencies?(browser = nil, force: nil)
|
|
12
|
+
return force unless force.nil?
|
|
13
|
+
|
|
14
|
+
Venetian.auto_install_dependencies && dependencies_to_install?(browser)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def install_dry_run(browser = nil)
|
|
18
|
+
Executable.capture("install-deps", *browser&.to_s, "--dry-run", echo: debug?)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def dependencies_to_install
|
|
22
|
+
@dependencies_to_install ||= {}
|
|
13
23
|
end
|
|
14
24
|
|
|
15
|
-
def
|
|
16
|
-
|
|
25
|
+
def debug?
|
|
26
|
+
ENV.fetch("VENETIAN_DEBUG", nil)
|
|
17
27
|
end
|
|
18
28
|
end
|
|
19
29
|
|
|
@@ -29,18 +39,39 @@ module Venetian
|
|
|
29
39
|
end
|
|
30
40
|
|
|
31
41
|
# Installs a browser. Raises InstallError if installation fails.
|
|
32
|
-
def self.install(browser = nil, install_dependencies:
|
|
33
|
-
Venetian.system "install", *browser&.to_s,
|
|
34
|
-
|
|
42
|
+
def self.install(browser = nil, install_dependencies: nil)
|
|
43
|
+
Venetian.system "install", *browser&.to_s,
|
|
44
|
+
*("--with-deps" if install_dependencies?(browser, force: install_dependencies)),
|
|
45
|
+
exception: true, echo: debug?
|
|
35
46
|
rescue StandardError => e
|
|
36
47
|
raise InstallError, e.message
|
|
37
48
|
end
|
|
38
49
|
|
|
39
|
-
#
|
|
40
|
-
|
|
41
|
-
|
|
50
|
+
# Output from a dry run where Playwright couldn't spawn its package manager, so has no way to install dependencies.
|
|
51
|
+
NO_PACKAGE_MANAGER_OUTPUT = "ENOENT" # :nodoc:
|
|
52
|
+
|
|
53
|
+
# Returns true if Playwright's dependency installer has something to install on the current OS for a browser,
|
|
54
|
+
# or for the default browsers if none given.
|
|
55
|
+
#
|
|
56
|
+
# On Linux, the dry run simulates the install with the package manager, exiting non-zero if packages are missing or
|
|
57
|
+
# if it can't simulate (e.g. no package lists yet, which the installer fixes by updating them first), unless there's
|
|
58
|
+
# no package manager it can use. On Windows, the dry run only prints the command it would run, so there is always
|
|
59
|
+
# something to install.
|
|
60
|
+
def self.dependencies_to_install?(browser = nil, force: false)
|
|
61
|
+
return true if Gem.win_platform?
|
|
62
|
+
|
|
63
|
+
dependencies_to_install.delete(browser&.to_s) if force
|
|
64
|
+
dependencies_to_install.fetch(browser&.to_s) do |key|
|
|
65
|
+
dependencies_to_install[key] = install_dry_run(browser).then do |output, status|
|
|
66
|
+
!status.success? && !output.include?(NO_PACKAGE_MANAGER_OUTPUT)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
42
70
|
|
|
43
|
-
|
|
71
|
+
def self.dependencies_supported?(...) # :nodoc:
|
|
72
|
+
warn "Venetian::BrowserInstaller.dependencies_supported? is deprecated; use dependencies_to_install? instead.",
|
|
73
|
+
category: :deprecated, uplevel: 1
|
|
74
|
+
dependencies_to_install?(...)
|
|
44
75
|
end
|
|
45
76
|
end
|
|
46
77
|
end
|
|
@@ -2,13 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
module Venetian
|
|
4
4
|
module BrowserRunnerExtensions # :nodoc:
|
|
5
|
+
ALTERNATIVE_DRIVER_OPTIONS = %i[playwright_cli_executable_path playwright_server_endpoint_url
|
|
6
|
+
browser_server_endpoint_url].freeze
|
|
7
|
+
|
|
8
|
+
def self.browser_to_preinstall_from(options)
|
|
9
|
+
(options[:browser_type] || :chromium).to_sym if options.values_at(*ALTERNATIVE_DRIVER_OPTIONS).none?
|
|
10
|
+
end
|
|
11
|
+
|
|
5
12
|
def initialize(options = {}, *args)
|
|
6
|
-
@
|
|
13
|
+
@venetian_browser = BrowserRunnerExtensions.browser_to_preinstall_from(options) if Venetian.auto_install_browsers
|
|
7
14
|
super
|
|
8
15
|
end
|
|
9
16
|
|
|
10
17
|
def start
|
|
11
|
-
BrowserInstaller.install(@
|
|
18
|
+
BrowserInstaller.install(@venetian_browser) if @venetian_browser
|
|
12
19
|
super
|
|
13
20
|
end
|
|
14
21
|
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "venetian/version"
|
|
4
|
+
require "venetian/upstream"
|
|
5
|
+
require "venetian/executable"
|
|
6
|
+
require "venetian/browser_installer"
|
|
7
|
+
require "venetian/gemspec"
|
|
8
|
+
|
|
9
|
+
module Venetian # :nodoc:
|
|
10
|
+
class << self
|
|
11
|
+
attr_accessor :auto_install_dependencies
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class Error < StandardError; end
|
|
15
|
+
|
|
16
|
+
self.auto_install_dependencies = true
|
|
17
|
+
|
|
18
|
+
def self.execute(*, echo: true, **)
|
|
19
|
+
Executable.execute(*, echo: echo, **)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.system(*, echo: true, **)
|
|
23
|
+
Executable.system(*, echo: echo, **)
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/venetian/executable.rb
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "open3"
|
|
4
|
+
require "shellwords"
|
|
5
|
+
|
|
3
6
|
module Venetian
|
|
4
7
|
# # \Executable
|
|
5
8
|
#
|
|
@@ -7,6 +10,10 @@ module Venetian
|
|
|
7
10
|
module Executable
|
|
8
11
|
class Executor # :nodoc:
|
|
9
12
|
public :system, :exec
|
|
13
|
+
|
|
14
|
+
def capture(*command)
|
|
15
|
+
Open3.capture2e(*command)
|
|
16
|
+
end
|
|
10
17
|
end
|
|
11
18
|
|
|
12
19
|
DEFAULT_DIR = File.expand_path(File.join(__dir__, "..", "..", "exe")) # :nodoc:
|
|
@@ -109,11 +116,31 @@ module Venetian
|
|
|
109
116
|
end
|
|
110
117
|
end
|
|
111
118
|
|
|
119
|
+
# Runs the Playwright executable with the given arguments, returning its combined output and status.
|
|
120
|
+
def capture(*args, echo: true)
|
|
121
|
+
[*base_command, *args].then do |command|
|
|
122
|
+
puts command.shelljoin if echo
|
|
123
|
+
executor.capture(*command).tap do |output, _|
|
|
124
|
+
puts output if echo
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
112
129
|
# Returns the base command to execute Playwright.
|
|
113
130
|
def base_command
|
|
114
131
|
[path, File.join(File.dirname(path), "package", "cli.js")]
|
|
115
132
|
end
|
|
116
133
|
|
|
134
|
+
# Returns the base command as a single string, as expected by +:playwright_cli_executable_path+.
|
|
135
|
+
def cli_command
|
|
136
|
+
if Gem.win_platform?
|
|
137
|
+
base_command.collect { |arg| %("#{arg}") }
|
|
138
|
+
.join(" ")
|
|
139
|
+
else
|
|
140
|
+
base_command.shelljoin
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
117
144
|
private
|
|
118
145
|
|
|
119
146
|
def ensure_exe_dir_exists!
|
data/lib/venetian/gemspec.rb
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "playwright"
|
|
4
|
+
|
|
5
|
+
require "venetian/core"
|
|
6
|
+
|
|
7
|
+
module Venetian # :nodoc:
|
|
8
|
+
# Starts Playwright using the bundled executable. Accepts the same arguments as +Playwright.create+,
|
|
9
|
+
# so +:playwright_cli_executable_path+ can still be overridden.
|
|
10
|
+
def self.start(**options, &)
|
|
11
|
+
options[:playwright_cli_executable_path] ||= Executable.cli_command
|
|
12
|
+
Playwright.create(**options, &)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
module Venetian
|
|
4
4
|
module PlaywrightCreateExtensions # :nodoc:
|
|
5
5
|
def initialize(options = {}, *)
|
|
6
|
-
|
|
6
|
+
unless options[:playwright_cli_executable_path]
|
|
7
|
+
options = options.merge(playwright_cli_executable_path: Executable.cli_command)
|
|
8
|
+
end
|
|
9
|
+
super
|
|
7
10
|
end
|
|
8
11
|
end
|
|
9
12
|
end
|
|
@@ -16,7 +16,9 @@ module Venetian
|
|
|
16
16
|
def driven_by(driver, options: {}, **)
|
|
17
17
|
super
|
|
18
18
|
|
|
19
|
-
self.venetian_browser_type = driver == :playwright
|
|
19
|
+
self.venetian_browser_type = if driver == :playwright
|
|
20
|
+
BrowserRunnerExtensions.browser_to_preinstall_from(options)
|
|
21
|
+
end
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
def install_playwright_browsers
|
data/lib/venetian/upstream.rb
CHANGED
data/lib/venetian/version.rb
CHANGED
data/lib/venetian.rb
CHANGED
|
@@ -2,33 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
require "capybara/playwright"
|
|
4
4
|
|
|
5
|
-
require "venetian/
|
|
6
|
-
require "venetian/upstream"
|
|
7
|
-
require "venetian/executable"
|
|
5
|
+
require "venetian/playwright"
|
|
8
6
|
require "venetian/playwright_create_extensions"
|
|
9
|
-
require "venetian/browser_installer"
|
|
10
7
|
require "venetian/browser_runner_extensions"
|
|
11
|
-
require "venetian/
|
|
12
|
-
require "venetian/railtie" if defined? Rails
|
|
8
|
+
require "venetian/railtie" if defined?(Rails::Railtie)
|
|
13
9
|
|
|
14
10
|
# # Venetian
|
|
15
11
|
#
|
|
16
|
-
# Native Playwright driver for
|
|
12
|
+
# Native Playwright driver for Ruby.
|
|
17
13
|
module Venetian
|
|
18
14
|
class << self
|
|
19
|
-
attr_accessor :auto_install_browsers
|
|
15
|
+
attr_accessor :auto_install_browsers
|
|
20
16
|
end
|
|
21
17
|
|
|
22
|
-
class Error < StandardError; end
|
|
23
|
-
|
|
24
18
|
self.auto_install_browsers = true
|
|
25
|
-
self.auto_install_dependencies = true
|
|
26
|
-
|
|
27
|
-
def self.execute(*, echo: true, **)
|
|
28
|
-
Executable.execute(*, echo: echo, **)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def self.system(*, echo: true, **)
|
|
32
|
-
Executable.system(*, echo: echo, **)
|
|
33
|
-
end
|
|
34
19
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: venetian
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Justin Malčić
|
|
@@ -55,8 +55,10 @@ files:
|
|
|
55
55
|
- lib/venetian.rb
|
|
56
56
|
- lib/venetian/browser_installer.rb
|
|
57
57
|
- lib/venetian/browser_runner_extensions.rb
|
|
58
|
+
- lib/venetian/core.rb
|
|
58
59
|
- lib/venetian/executable.rb
|
|
59
60
|
- lib/venetian/gemspec.rb
|
|
61
|
+
- lib/venetian/playwright.rb
|
|
60
62
|
- lib/venetian/playwright_create_extensions.rb
|
|
61
63
|
- lib/venetian/railtie.rb
|
|
62
64
|
- lib/venetian/system_test_case_extension.rb
|