capybara-playwright-driver 0.1.4 → 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 +4 -4
- data/README.md +5 -1
- data/capybara-playwright.gemspec +3 -3
- data/lib/capybara/playwright/browser.rb +27 -1
- data/lib/capybara/playwright/browser_runner.rb +99 -0
- data/lib/capybara/playwright/driver.rb +5 -19
- data/lib/capybara/playwright/version.rb +1 -1
- data/lib/capybara/playwright.rb +1 -0
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbeebaa83a4010e3b6e99abbc5fe3bcd6fc4e0b61c13f4247f318d5bb9bba039
|
4
|
+
data.tar.gz: b2fbb62062ebda5efddf8ff7a8b2c185b6d725af2480c7638211f7114c1412cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91dd078211a3464e311b7bbd8a92e2038cddc1bd4750b5b4259e011caf089cbcdd2c48127c0c55467053e91d08014b36e77c00c153004732aef0301d90c1e4eb
|
7
|
+
data.tar.gz: ef7f8050310b3dffc69add62f810cd4df52ee28f10dc1bc35eabd62e33a042322b5d88ead040a468bb1e0a9838f31cdde02793e62ba6dfab4088a347b67aaeed
|
data/README.md
CHANGED
@@ -2,12 +2,14 @@
|
|
2
2
|
|
3
3
|
# 🎭 Playwright driver for Capybara
|
4
4
|
|
5
|
-
|
5
|
+
Make it easy to introduce Playwright into your Rails application.
|
6
6
|
|
7
7
|
```ruby
|
8
8
|
gem 'capybara-playwright-driver'
|
9
9
|
```
|
10
10
|
|
11
|
+
**NOTE**: If you want to use Playwright-native features (such as auto-waiting, various type of locators, ...), [consider using playwright-ruby-client directly](https://playwright-ruby-client.vercel.app/docs/article/guides/rails_integration_with_null_driver).
|
12
|
+
|
11
13
|
## Examples
|
12
14
|
|
13
15
|
```ruby
|
@@ -38,6 +40,8 @@ all('.repo-list-item').each do |li|
|
|
38
40
|
end
|
39
41
|
```
|
40
42
|
|
43
|
+
Refer the [documentation](https://playwright-ruby-client.vercel.app/docs/article/guides/rails_integration) for more detailed configuration.
|
44
|
+
|
41
45
|
## License
|
42
46
|
|
43
47
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/capybara-playwright.gemspec
CHANGED
@@ -26,13 +26,13 @@ Gem::Specification.new do |spec|
|
|
26
26
|
|
27
27
|
spec.required_ruby_version = '>= 2.4'
|
28
28
|
spec.add_dependency 'capybara'
|
29
|
-
spec.add_dependency 'playwright-ruby-client', '>=
|
29
|
+
spec.add_dependency 'playwright-ruby-client', '>= 1.16.0'
|
30
30
|
spec.add_development_dependency 'allure-rspec'
|
31
|
-
spec.add_development_dependency 'bundler', '~> 2.
|
31
|
+
spec.add_development_dependency 'bundler', '~> 2.3.10'
|
32
32
|
spec.add_development_dependency 'launchy', '>= 2.0.4'
|
33
33
|
spec.add_development_dependency 'pry-byebug'
|
34
34
|
spec.add_development_dependency 'rake', '~> 13.0.3'
|
35
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.11.0'
|
36
36
|
spec.add_development_dependency 'rubocop-rspec'
|
37
37
|
spec.add_development_dependency 'sinatra', '>= 1.4.0'
|
38
38
|
spec.add_development_dependency 'webrick'
|
@@ -165,6 +165,15 @@ module Capybara
|
|
165
165
|
wrap_node(result)
|
166
166
|
end
|
167
167
|
|
168
|
+
def active_element
|
169
|
+
el = @playwright_page.capybara_current_frame.evaluate_handle('() => document.activeElement')
|
170
|
+
if el
|
171
|
+
Node.new(@driver, @playwright_page, el)
|
172
|
+
else
|
173
|
+
nil
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
168
177
|
# Not used by Capybara::Session.
|
169
178
|
# Intended to be directly called by user.
|
170
179
|
def video_path
|
@@ -328,7 +337,24 @@ module Capybara
|
|
328
337
|
when ::Playwright::ElementHandle
|
329
338
|
Node.new(@driver, @playwright_page, arg)
|
330
339
|
when ::Playwright::JSHandle
|
331
|
-
arg.
|
340
|
+
obj_type, is_array = arg.evaluate('obj => [typeof obj, Array.isArray(obj)]')
|
341
|
+
if obj_type == 'object'
|
342
|
+
if is_array
|
343
|
+
# Firefox often include 'toJSON' into properties.
|
344
|
+
# https://github.com/microsoft/playwright/issues/7015
|
345
|
+
#
|
346
|
+
# Get rid of non-numeric entries.
|
347
|
+
arg.properties.select { |key, _| key.to_i.to_s == key.to_s }.map do |_, value|
|
348
|
+
wrap_node(value)
|
349
|
+
end
|
350
|
+
else
|
351
|
+
arg.properties.map do |key, value|
|
352
|
+
[key, wrap_node(value)]
|
353
|
+
end.to_h
|
354
|
+
end
|
355
|
+
else
|
356
|
+
arg.json_value
|
357
|
+
end
|
332
358
|
else
|
333
359
|
arg
|
334
360
|
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module Capybara
|
2
|
+
module Playwright
|
3
|
+
# playwright-ruby-client provides 3 methods to launch/connect browser.
|
4
|
+
#
|
5
|
+
# Playwright.create do |playwright|
|
6
|
+
# playwright.chromium.launch do |browser|
|
7
|
+
#
|
8
|
+
# Playwright.connect_to_playwright_server do |playwright| ...
|
9
|
+
# playwright.chromium.launch do |browser|
|
10
|
+
#
|
11
|
+
# Playwright.connect_to_browser_server do |browser| ...
|
12
|
+
#
|
13
|
+
# This class provides start/stop methods for driver.
|
14
|
+
# This is responsible for
|
15
|
+
# - managing PlaywrightExecution
|
16
|
+
# - launching browser with given option if needed
|
17
|
+
class BrowserRunner
|
18
|
+
class PlaywrightConnectToPlaywrightServer
|
19
|
+
def initialize(endpoint_url, options)
|
20
|
+
@ws_endpoint = endpoint_url
|
21
|
+
@browser_type = options[:browser_type] || :chromium
|
22
|
+
unless %i(chromium firefox webkit).include?(@browser_type)
|
23
|
+
raise ArgumentError.new("Unknown browser_type: #{@browser_type}")
|
24
|
+
end
|
25
|
+
@browser_options = BrowserOptions.new(options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def playwright_execution
|
29
|
+
@playwright_execution ||= ::Playwright.connect_to_playwright_server(@ws_endpoint)
|
30
|
+
end
|
31
|
+
|
32
|
+
def playwright_browser
|
33
|
+
browser_type = playwright_execution.playwright.send(@browser_type)
|
34
|
+
browser_options = @browser_options.value
|
35
|
+
browser_type.launch(**browser_options)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class PlaywrightConnectToBrowserServer
|
40
|
+
def initialize(endpoint_url)
|
41
|
+
@ws_endpoint = endpoint_url
|
42
|
+
end
|
43
|
+
|
44
|
+
def playwright_execution
|
45
|
+
@playwright_execution ||= ::Playwright.connect_to_browser_server(@ws_endpoint)
|
46
|
+
end
|
47
|
+
|
48
|
+
def playwright_browser
|
49
|
+
playwright_execution.browser
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class PlaywrightCreate
|
54
|
+
def initialize(options)
|
55
|
+
@playwright_cli_executable_path = options[:playwright_cli_executable_path] || 'npx playwright'
|
56
|
+
@browser_type = options[:browser_type] || :chromium
|
57
|
+
unless %i(chromium firefox webkit).include?(@browser_type)
|
58
|
+
raise ArgumentError.new("Unknown browser_type: #{@browser_type}")
|
59
|
+
end
|
60
|
+
@browser_options = BrowserOptions.new(options)
|
61
|
+
end
|
62
|
+
|
63
|
+
def playwright_execution
|
64
|
+
@playwright_execution ||= ::Playwright.create(
|
65
|
+
playwright_cli_executable_path: @playwright_cli_executable_path,
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
def playwright_browser
|
70
|
+
browser_type = playwright_execution.playwright.send(@browser_type)
|
71
|
+
browser_options = @browser_options.value
|
72
|
+
browser_type.launch(**browser_options)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def initialize(options)
|
77
|
+
@runner =
|
78
|
+
if options[:playwright_server_endpoint_url]
|
79
|
+
PlaywrightConnectToPlaywrightServer.new(options[:playwright_server_endpoint_url], options)
|
80
|
+
elsif options[:browser_server_endpoint_url]
|
81
|
+
PlaywrightConnectToBrowserServer.new(options[:browser_server_endpoint_url])
|
82
|
+
else
|
83
|
+
PlaywrightCreate.new(options)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# @return [::Playwright::Browser]
|
88
|
+
def start
|
89
|
+
@playwright_execution = @runner.playwright_execution
|
90
|
+
@runner.playwright_browser
|
91
|
+
end
|
92
|
+
|
93
|
+
def stop
|
94
|
+
@playwright_execution&.stop
|
95
|
+
@playwright_execution = nil
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -7,20 +7,14 @@ module Capybara
|
|
7
7
|
include DriverExtension
|
8
8
|
|
9
9
|
def initialize(app, **options)
|
10
|
-
@
|
11
|
-
@browser_type = options[:browser_type] || :chromium
|
12
|
-
unless %i(chromium firefox webkit).include?(@browser_type)
|
13
|
-
raise ArgumentError.new("Unknown browser_type: #{@browser_type}")
|
14
|
-
end
|
15
|
-
|
16
|
-
@browser_options = BrowserOptions.new(options)
|
10
|
+
@browser_runner = BrowserRunner.new(options)
|
17
11
|
@page_options = PageOptions.new(options)
|
18
12
|
end
|
19
13
|
|
20
14
|
def wait?; true; end
|
21
15
|
def needs_server?; true; end
|
22
16
|
|
23
|
-
def browser
|
17
|
+
private def browser
|
24
18
|
@browser ||= ::Capybara::Playwright::Browser.new(
|
25
19
|
driver: self,
|
26
20
|
playwright_browser: playwright_browser,
|
@@ -43,22 +37,13 @@ module Capybara
|
|
43
37
|
exit @exit_status if @exit_status # Force exit with stored status
|
44
38
|
end
|
45
39
|
|
46
|
-
|
47
|
-
browser_options = @browser_options.value
|
48
|
-
browser_type.launch(**browser_options)
|
49
|
-
end
|
50
|
-
|
51
|
-
private def playwright_execution
|
52
|
-
@playwright_execution ||= ::Playwright.create(
|
53
|
-
playwright_cli_executable_path: @playwright_cli_executable_path,
|
54
|
-
)
|
40
|
+
@browser_runner.start
|
55
41
|
end
|
56
42
|
|
57
43
|
private def quit
|
58
44
|
@playwright_browser&.close
|
59
45
|
@playwright_browser = nil
|
60
|
-
@
|
61
|
-
@playwright_execution = nil
|
46
|
+
@browser_runner.stop
|
62
47
|
end
|
63
48
|
|
64
49
|
def reset!
|
@@ -112,6 +97,7 @@ module Capybara
|
|
112
97
|
def_delegator(:browser, :save_screenshot)
|
113
98
|
def_delegator(:browser, :response_headers)
|
114
99
|
def_delegator(:browser, :status_code)
|
100
|
+
def_delegator(:browser, :active_element)
|
115
101
|
def_delegator(:browser, :send_keys)
|
116
102
|
def_delegator(:browser, :switch_to_frame)
|
117
103
|
def_delegator(:browser, :current_window_handle)
|
data/lib/capybara/playwright.rb
CHANGED
@@ -4,6 +4,7 @@ require 'capybara'
|
|
4
4
|
require 'playwright'
|
5
5
|
|
6
6
|
require 'capybara/playwright/browser'
|
7
|
+
require 'capybara/playwright/browser_runner'
|
7
8
|
require 'capybara/playwright/browser_options'
|
8
9
|
require 'capybara/playwright/dialog_event_handler'
|
9
10
|
require 'capybara/playwright/driver'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-playwright-driver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YusukeIwaki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.16.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 1.16.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: allure-rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 2.
|
61
|
+
version: 2.3.10
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 2.
|
68
|
+
version: 2.3.10
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: launchy
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 3.
|
117
|
+
version: 3.11.0
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 3.
|
124
|
+
version: 3.11.0
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rubocop-rspec
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,6 +184,7 @@ files:
|
|
184
184
|
- lib/capybara/playwright.rb
|
185
185
|
- lib/capybara/playwright/browser.rb
|
186
186
|
- lib/capybara/playwright/browser_options.rb
|
187
|
+
- lib/capybara/playwright/browser_runner.rb
|
187
188
|
- lib/capybara/playwright/dialog_event_handler.rb
|
188
189
|
- lib/capybara/playwright/driver.rb
|
189
190
|
- lib/capybara/playwright/driver_extension.rb
|
@@ -211,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
212
|
- !ruby/object:Gem::Version
|
212
213
|
version: '0'
|
213
214
|
requirements: []
|
214
|
-
rubygems_version: 3.
|
215
|
+
rubygems_version: 3.3.7
|
215
216
|
signing_key:
|
216
217
|
specification_version: 4
|
217
218
|
summary: Playwright driver for Capybara
|