venetian 0.2.3-aarch64-linux → 0.3.0-aarch64-linux

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
  SHA256:
3
- metadata.gz: 45bed133b8d491e90d71f7cebef7a6955a25aa78fd81559fe99cd8dcec007f8a
4
- data.tar.gz: 33be7335e43c6f72ab4920558c416cff63261195c17fe3f6e249c4a47f71aeb2
3
+ metadata.gz: 0ad6579fb432f5212b65bcfbf8238dca41146e301f3b7b681e156de11f6210c1
4
+ data.tar.gz: 75fd821fb658a6d7f5e65e008f81f5b49411bd752cf85974c8e06c608ab5bd34
5
5
  SHA512:
6
- metadata.gz: 304564e2828afa47acf79bb2b281979365dd29f187fb86db251db75de295c6c8446cb0e66b21edc254a9e24c0c95be40f4071241f383d76b1c83ae56a0c64328
7
- data.tar.gz: cacce70aad1c8eb3c771c4c25eeb7f08860a86899a304ed6c73fa294628eae81fd06c0a355b6c30152a9ebb80a0fdd06e5c4c968165bbf4472c5de7939e5511e
6
+ metadata.gz: 305fafc06f82a8e7cea8c8e699358317e2781d3beb0b8efdb46ef3ac8a08628abb79de1b52c0c1aef0be5864cd4365c4c2e7ab3c25413f7ab044753b4634b4e3
7
+ data.tar.gz: e1c1b3a383105653bf5601d5aaa11f913a3ed4dd95e3686fd2732c0c7d36aebf0d8be574b13dcc5f167240b736ffdc0084b1acd846c4a5a38db5df6526230ad8
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
- The gem will automatically install a browser and dependencies for you before attempting to use it.
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 the gem is required.
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
@@ -1,7 +1,7 @@
1
1
  #! /usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "venetian"
4
+ require "venetian/core"
5
5
 
6
6
  begin
7
7
  Venetian.execute(*ARGV, echo: ENV.fetch("VENETIAN_DEBUG", nil))
@@ -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
- Venetian.auto_install_dependencies && dependencies_supported?
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 install_dry_run
16
- Venetian.system "install-deps", "--dry-run", exception: false, echo: ENV.fetch("VENETIAN_DEBUG", nil)
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: install_dependencies?)
33
- Venetian.system "install", *browser&.to_s, *("--with-deps" if install_dependencies),
34
- exception: true, echo: ENV.fetch("VENETIAN_DEBUG", nil)
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
- # Returns true if the current OS supports Playwright's dependency installer.
40
- def self.dependencies_supported?(force: false)
41
- return @dependencies_supported unless @dependencies_supported.nil? || force
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
- @dependencies_supported = install_dry_run || false
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
- @venetian_browser_type = options[:browser_type] || :chromium
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(@venetian_browser_type) if Venetian.auto_install_browsers
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
@@ -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!
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "pathname"
4
+
3
5
  module Venetian
4
6
  GEMSPEC = Gem.loaded_specs.values.reverse.find do |spec|
5
7
  spec.gem_dir == Pathname.new(__dir__).join("..", "..").expand_path.to_path
@@ -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
- super({ playwright_cli_executable_path: Executable.base_command.shelljoin }.merge(options), *)
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 ? options.fetch(:browser_type, :chromium).to_sym : nil
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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "playwright"
3
+ require "playwright/version"
4
4
 
5
5
  module Venetian
6
6
  # # \Upstream
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Venetian
4
- VERSION = "0.2.3"
4
+ VERSION = "0.3.0"
5
5
  COMPATIBLE_PLAYWRIGHT_VERSION = "1.63.0"
6
6
  end
data/lib/venetian.rb CHANGED
@@ -2,33 +2,18 @@
2
2
 
3
3
  require "capybara/playwright"
4
4
 
5
- require "venetian/version"
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/gemspec"
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 Capybara.
12
+ # Native Playwright driver for Ruby.
17
13
  module Venetian
18
14
  class << self
19
- attr_accessor :auto_install_browsers, :auto_install_dependencies
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.2.3
4
+ version: 0.3.0
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - Justin Malčić
@@ -171,8 +171,10 @@ files:
171
171
  - lib/venetian.rb
172
172
  - lib/venetian/browser_installer.rb
173
173
  - lib/venetian/browser_runner_extensions.rb
174
+ - lib/venetian/core.rb
174
175
  - lib/venetian/executable.rb
175
176
  - lib/venetian/gemspec.rb
177
+ - lib/venetian/playwright.rb
176
178
  - lib/venetian/playwright_create_extensions.rb
177
179
  - lib/venetian/railtie.rb
178
180
  - lib/venetian/system_test_case_extension.rb