yusukeiwaki / capybara-playwright-driver Goto Github PK
View Code? Open in Web Editor NEWPlaywright driver for Capybara
License: MIT License
Playwright driver for Capybara
License: MIT License
There is a common Rails pattern for uploading files:
attach_file "post[attachment]", Rails.root.join('spec', 'fixtures', 'image.png'), visible: false
This resulted in an error with the following backtrace:
file must be a String or File. (ArgumentError)
/home/ubuntu/.asdf/installs/ruby/2.6.5/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-1.27.0/lib/playwright/input_files.rb:83:in `raise_argument_error'
/home/ubuntu/.asdf/installs/ruby/2.6.5/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-1.27.0/lib/playwright/input_files.rb:32:in `block in has_large_file?'
/home/ubuntu/.asdf/installs/ruby/2.6.5/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-1.27.0/lib/playwright/input_files.rb:25:in `any?'
/home/ubuntu/.asdf/installs/ruby/2.6.5/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-1.27.0/lib/playwright/input_files.rb:25:in `has_large_file?'
/home/ubuntu/.asdf/installs/ruby/2.6.5/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-1.27.0/lib/playwright/input_files.rb:15:in `as_method_and_params'
/home/ubuntu/.asdf/installs/ruby/2.6.5/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-1.27.0/lib/playwright/channel_owners/element_handle.rb:213:in `set_input_files'
/home/ubuntu/.asdf/installs/ruby/2.6.5/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-1.27.0/lib/playwright_api/element_handle.rb:449:in `set_input_files'
/home/ubuntu/.asdf/installs/ruby/2.6.5/lib/ruby/gems/2.6.0/gems/capybara-playwright-driver-0.3.0/lib/capybara/playwright/node.rb:248:in `set'
/home/ubuntu/.asdf/installs/ruby/2.6.5/lib/ruby/gems/2.6.0/gems/capybara-playwright-driver-0.3.0/lib/capybara/playwright/node.rb:208:in `set'
/home/ubuntu/.asdf/installs/ruby/2.6.5/lib/ruby/gems/2.6.0/gems/capybara-3.36.0/lib/capybara/node/element.rb:123:in `block in set'
/home/ubuntu/.asdf/installs/ruby/2.6.5/lib/ruby/gems/2.6.0/gems/capybara-3.36.0/lib/capybara/node/base.rb:83:in `synchronize'
/home/ubuntu/.asdf/installs/ruby/2.6.5/lib/ruby/gems/2.6.0/gems/capybara-3.36.0/lib/capybara/node/element.rb:123:in `set'
/home/ubuntu/.asdf/installs/ruby/2.6.5/lib/ruby/gems/2.6.0/gems/capybara-3.36.0/lib/capybara/node/actions.rb:304:in `attach_file'
/home/ubuntu/.asdf/installs/ruby/2.6.5/lib/ruby/gems/2.6.0/gems/capybara-3.36.0/lib/capybara/session.rb:778:in `block (2 levels) in <class:Session>'
/home/ubuntu/.asdf/installs/ruby/2.6.5/lib/ruby/gems/2.6.0/gems/capybara-3.36.0/lib/capybara/dsl.rb:58:in `block (2 levels) in <module:DSL>'
Upon investigation, I found that Rails.root.join
results in a Pathname
object.
As a workaround, I am converting all pathnames to string using .to_s
but IMO it would be great if this is supported natively, so it matches Capybara behavior.
# Monkey-patch Capybara::Playwright::Node::FileUpload#set to
# convert paths to String prior to passing them to Playwright.
#
# See: https://github.com/YusukeIwaki/capybara-playwright-driver/issues/52
#
module Capybara::Playwright::Node::FileUploadSetHack
def set(value, **options)
if value.is_a?(Array)
value = value.map(&:to_s)
else
value = value.to_s
end
super(value, **options)
end
end
Capybara::Playwright::Node::FileUpload.prepend(Capybara::Playwright::Node::FileUploadSetHack)
Hello, we are curious about how viable this project is for future use? Is it being maintained and used?
Thanks!
Hey, I get this error when I try to use it:
Capybara.register_driver(:playwright) do |_|
Capybara::Playwright::Driver.new(nil,browser_type: :chromium, headless: false)
end
session = Capybara::Session.new(:playwright)
session.visit "https://google.com"
trace:
Failure/Error: visit 'https://google.com'
Playwright::Error:
Error: stack[83].file: expected string, got object
# /home/superuser/.rvm/gems/ruby-3.0.2/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/promises.rb:1257:in `wait_until_resolved!'
# /home/superuser/.rvm/gems/ruby-3.0.2/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/promises.rb:1471:in `value!'
# /home/superuser/.rvm/gems/ruby-3.0.2/gems/playwright-ruby-client-1.16.0/lib/playwright/connection.rb:68:in `send_message_to_server'
# /home/superuser/.rvm/gems/ruby-3.0.2/gems/playwright-ruby-client-1.16.0/lib/playwright/channel.rb:34:in `block in send_message_to_server_result'
# /home/superuser/.rvm/gems/ruby-3.0.2/gems/playwright-ruby-client-1.16.0/lib/playwright/channel.rb:67:in `with_logging'
# /home/superuser/.rvm/gems/ruby-3.0.2/gems/playwright-ruby-client-1.16.0/lib/playwright/channel.rb:33:in `send_message_to_server_result'
# /home/superuser/.rvm/gems/ruby-3.0.2/gems/playwright-ruby-client-1.16.0/lib/playwright/channel.rb:20:in `send_message_to_server'
# /home/superuser/.rvm/gems/ruby-3.0.2/gems/playwright-ruby-client-1.16.0/lib/playwright/channel_owners/browser_type.rb:14:in `launch'
# /home/superuser/.rvm/gems/ruby-3.0.2/gems/playwright-ruby-client-1.16.0/lib/playwright_api/browser_type.rb:88:in `launch'
# /home/superuser/.rvm/gems/ruby-3.0.2/gems/capybara-playwright-driver-0.1.6/lib/capybara/playwright/browser_runner.rb:72:in `playwright_browser'
# /home/superuser/.rvm/gems/ruby-3.0.2/gems/capybara-playwright-driver-0.1.6/lib/capybara/playwright/browser_runner.rb:90:in `start'
# /home/superuser/.rvm/gems/ruby-3.0.2/gems/capybara-playwright-driver-0.1.6/lib/capybara/playwright/driver.rb:40:in `create_playwright_browser'
# /home/superuser/.rvm/gems/ruby-3.0.2/gems/capybara-playwright-driver-0.1.6/lib/capybara/playwright/driver.rb:27:in `playwright_browser'
# /home/superuser/.rvm/gems/ruby-3.0.2/gems/capybara-playwright-driver-0.1.6/lib/capybara/playwright/driver.rb:20:in `browser'
# /home/superuser/.rvm/gems/ruby-3.0.2/gems/capybara-3.36.0/lib/capybara/session.rb:278:in `visit'
this works fine for me
Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
playwright.chromium.launch(headless: false) do |browser|
page = browser.new_page
page.goto('https://google.com')
end
end
Thanks for a phenomenal open-source project. I haven't been able to figure out how to control the screen size and the screenshot size.
I'd love it a little bigger, and it doesn't look like the default settings for capybara or system tests does anything.
3: from /Users/yusuke-iwaki/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-0.5.10/lib/playwright/playwright_api.rb:34:in `wrap'
2: from /Users/yusuke-iwaki/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-0.5.10/lib/playwright/playwright_api.rb:34:in `new'
1: from /Users/yusuke-iwaki/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/capybara-playwright-driver-0.0.0.pre.r1/lib/capybara/playwright/page.rb:7:in `initialize'
/Users/yusuke-iwaki/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-0.5.10/lib/playwright/playwright_api.rb:100:in `initialize': wrong number of arguments (given 2, expected 1) (ArgumentError)
Hey!
I would like to get JavaScript output from browser side to ruby.
Are there any possibilities to do so with this driver?
When we use Capybara in Rails app with docker-compose (Rails app + Playwright), Playwright.connect_to_server is required.
https://zenn.dev/imaginary/articles/6ed45b2352896f
This article shows a workaround with monkey-patching
module CapybaraPlaywrightDriverPatch
private def playwright_execution
@playwright_execution ||= ::Playwright.connect_to_playwright_server('ws://playwright:4545/ws')
end
end
Capybara::Playwright::Driver.prepend(CapybaraPlaywrightDriverPatch)
The feature for recording video of failed examples are already supported, however tracing is not supported.
A organization tried hard for configuring tracing and seems to be succeeded in postmortem of the failed tests using GitHub Actions.
before do
# Ensure playwright page is initialized.
Capybara.current_session.driver.send(:browser)
Capybara.current_session.driver.with_playwright_page do |playwright_page|
playwright_page.context.tracing.start(title: example.metadata[:full_description], screenshots: true, snapshots: true)
end
end
after do |example|
Capybara.current_session.driver.with_playwright_page do |playwright_page|
if failed?(example)
save_dir = Capybara.save_path.presence || "tmp/traces"
playwright_page.context.tracing.stop(path: File.join(save_dir, "#{example.metadata[:full_description]}.zip"))
else
playwright_page.context.tracing.stop
end
end
end
def failed?(example)
return true if example.exception
return false unless defined?(::RSpec::Expectations::FailureAggregator)
failure_notifier = ::RSpec::Support.failure_notifier
return false unless failure_notifier.is_a?(::RSpec::Expectations::FailureAggregator)
failure_notifier.failures.any? || failure_notifier.other_errors.any?
end
Since this idea is useful for most organizations, it would be better to enable easier configuration of tracing of failed examples.
A common pattern in testing is to do this:
click_on 'Confirm'
expect(page).to have_content "Thank you"
However, page
sometimes refers to the previous page. This resulted in an error like this:
Playwright::Error:
Error: Execution context was destroyed, most likely because of a navigation
This is my current ugly workaround. I monkeypatched Capybara::Session
to retry assert_text
3 times:
module Capybara::Session::PlaywrightSessionHasContentHack
def assert_text(*args, **options)
attempt = 0
loop do |i|
sleep 1 if attempt > 0
attempt += 1
begin
return super
rescue => e
raise e if attempt > 3
next if e.message.include?("Execution context was destroyed")
next if e.message.include?("Cannot find context with specified id")
raise e
end
end
end
end
Capybara::Session.prepend(Capybara::Session::PlaywrightSessionHasContentHack)
I'm randomly getting this error in my tests
Playwright::TimeoutError:
TimeoutError: Timeout 30000ms exceeded.
=========================== logs ===========================
navigating to "http://127.0.0.1:42245/forms/7/builder", waiting until "load"
============================================================
In my configuration I've increased the timeout to be 60000ms but still getting the same errors, seems like it's not respected?
Here's how my settings look like:
Capybara.register_driver(:playwright) do |app|
Capybara::Playwright::Driver.new(app,
browser_type: :chromium, # :chromium (default) or :firefox, :webkit
headless: true, # true for headless mode (default), false for headful mode.
timeout: 60_000 # ms
)
end
I've also set the max timeout
Capybara.default_max_wait_time = 60 # seconds
Any pointers would help.
Similar to here and the linked examples: https://world.hey.com/lewis/faster-rails-system-tests-f01df53b
I've been browsing through the code but it doesn't strike me as obvious how to achieve that.
This driver internally receives many errors like this. (This can be observed with environment variable DEBUG=1
)
SEND>{:id=>586, :guid=>"localUtils", :method=>"addStackToTracingNoReply", :params=>{:callData=>{:id=>585, :stack=>[{:file=>"/Users/yusuke-iwaki/src/github.com/YusukeIwaki/capybara-playwright-driver/spec/feature/example_spec.rb", :line=>91, :function=>"block (4 levels) in <top (required)>"}, {:file=>"/Users/yusuke-iwaki/src/github.com/YusukeIwaki/capybara-playwright-driver/lib/capybara/playwright/node.rb", :line=>22, :function=>"with_playwright_element_handle"}, {:file=>"/Users/yusuke-iwaki/src/github.com/YusukeIwaki/capybara-playwright-driver/spec/feature/example_spec.rb", :line=>91, :function=>"block (3 levels) in <top (required)>"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/capybara-3.39.2/lib/capybara/result.rb", :line=>48, :function=>"block in each"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/capybara-3.39.2/lib/capybara/result.rb", :line=>45, :function=>"loop"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/capybara-3.39.2/lib/capybara/result.rb", :line=>45, :function=>"each"}, {:file=>"/Users/yusuke-iwaki/src/github.com/YusukeIwaki/capybara-playwright-driver/spec/feature/example_spec.rb", :line=>90, :function=>"block (2 levels) in <top (required)>"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb", :line=>263, :function=>"instance_exec"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb", :line=>263, :function=>"block in run"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb", :line=>511, :function=>"block in with_around_and_singleton_context_hooks"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb", :line=>468, :function=>"block in with_around_example_hooks"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb", :line=>486, :function=>"block in run"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb", :line=>626, :function=>"block in run_around_example_hooks_for"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb", :line=>352, :function=>"call"}, {:file=>"/Users/yusuke-iwaki/src/github.com/YusukeIwaki/capybara-playwright-driver/spec/feature/example_spec.rb", :line=>8, :function=>"block (2 levels) in <top (required)>"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb", :line=>457, :function=>"instance_exec"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb", :line=>457, :function=>"instance_exec"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb", :line=>390, :function=>"execute_with"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb", :line=>628, :function=>"block (2 levels) in run_around_example_hooks_for"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb", :line=>352, :function=>"call"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb", :line=>629, :function=>"run_around_example_hooks_for"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb", :line=>486, :function=>"run"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb", :line=>468, :function=>"with_around_example_hooks"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb", :line=>511, :function=>"with_around_and_singleton_context_hooks"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example.rb", :line=>259, :function=>"run"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb", :line=>646, :function=>"block in run_examples"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb", :line=>642, :function=>"map"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb", :line=>642, :function=>"run_examples"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb", :line=>607, :function=>"run"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb", :line=>121, :function=>"block (3 levels) in run_specs"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb", :line=>121, :function=>"map"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb", :line=>121, :function=>"block (2 levels) in run_specs"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/configuration.rb", :line=>2068, :function=>"with_suite_hooks"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb", :line=>116, :function=>"block in run_specs"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/reporter.rb", :line=>74, :function=>"report"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb", :line=>115, :function=>"run_specs"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb", :line=>89, :function=>"run"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb", :line=>71, :function=>"run"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb", :line=>45, :function=>"invoke"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/rspec-core-3.11.0/exe/rspec", :line=>4, :function=>"<top (required)>"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/bin/rspec", :line=>25, :function=>"load"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/bin/rspec", :line=>25, :function=>"<top (required)>"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.10/lib/bundler/cli/exec.rb", :line=>58, :function=>"load"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.10/lib/bundler/cli/exec.rb", :line=>58, :function=>"kernel_load"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.10/lib/bundler/cli/exec.rb", :line=>23, :function=>"run"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.10/lib/bundler/cli.rb", :line=>483, :function=>"exec"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.10/lib/bundler/vendor/thor/lib/thor/command.rb", :line=>27, :function=>"run"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.10/lib/bundler/vendor/thor/lib/thor/invocation.rb", :line=>127, :function=>"invoke_command"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.10/lib/bundler/vendor/thor/lib/thor.rb", :line=>392, :function=>"dispatch"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.10/lib/bundler/cli.rb", :line=>31, :function=>"dispatch"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.10/lib/bundler/vendor/thor/lib/thor/base.rb", :line=>485, :function=>"start"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.10/lib/bundler/cli.rb", :line=>25, :function=>"start"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.10/exe/bundle", :line=>48, :function=>"block in <top (required)>"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.10/lib/bundler/friendly_errors.rb", :line=>103, :function=>"with_friendly_errors"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.3.10/exe/bundle", :line=>36, :function=>"<top (required)>"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/bin/bundle", :line=>25, :function=>"load"}, {:file=>"/Users/yusuke-iwaki/.rbenv/versions/3.1.3/bin/bundle", :line=>25, :function=>"<main>"}]}}}
RECV>{"id"=>586, "error"=>{"error"=>{"message"=>"callData.stack[0].column: expected number, got undefined", "stack"=>"Error: callData.stack[0].column: expected number, got undefined\n at tNumber (/Users/yusuke-iwaki/src/github.com/YusukeIwaki/capybara-playwright-driver/node_modules/playwright-core/lib/protocol/validatorPrimitives.js:47:9)\n at /Users/yusuke-iwaki/src/github.com/YusukeIwaki/capybara-playwright-driver/node_modules/playwright-core/lib/protocol/validatorPrimitives.js:108:21\n at /Users/yusuke-iwaki/src/github.com/YusukeIwaki/capybara-playwright-driver/node_modules/playwright-core/lib/protocol/validato...", "name"=>"Error"}}}
How can I check the status code of the response?
page.driver.status_code returns 0
Thanks
wait_for_load_state(state: 'networkidle')
のあと、sleepでdefault_max_wait_time以上の時間を待つと、下記エラーが出てテストに失敗します。
/Users/hoge/Desktop/playwright-test/node_modules/playwright-core/lib/server/dispatchers/dispatcher.js:344
originalMetadata.endTime = (0, _utils.monotonicTime)();
^
TypeError: Cannot set properties of undefined (setting 'endTime')
at DispatcherConnection.dispatch (/Users/hoge/Desktop/playwright-test/node_modules/playwright-core/lib/server/dispatchers/dispatcher.js:344:38)
at transport.onmessage (/Users/hoge/Desktop/playwright-test/node_modules/playwright-core/lib/cli/driver.js:52:57)
at Immediate.<anonymous> (/Users/hoge/Desktop/playwright-test/node_modules/playwright-core/lib/protocol/transport.js:77:34)
at process.processImmediate (node:internal/timers:478:21)
Node.js v20.11.0
再現コードは以下です。
require 'rails_helper'
RSpec.describe "Users", type: :system do
before do
driven_by(:playwright)
end
it "creates a User" do
visit new_user_path
Capybara.current_session.driver.with_playwright_page do |page|
page.wait_for_load_state(state: 'networkidle')
sleep 30
expect(page).to have_content("User was successfully created.")
end
end
end
フルバージョンのコードはこちらにあります。
https://github.com/kiyo-e/playwright-test
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.