概述
它比 Selenium 更快、更新,并且比 Capybara-DSL 具有更清晰的语法,请参阅讨论。
注意 Playwright 可以与 Capybara DSL 一起使用,这对于现有项目来说听起来不错。但是,至少在我的测试中,无法对其进行配置以使用 Capybara-DSL 编写的现有规范得以保留。我不得不重写它们。
源自文档
设置
类似 playwright_helper 的文件
require 'rails_helper' require 'capybara' require 'playwright' RSpec.configure do |config| # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Docs https://playwright-ruby-client.vercel.app/docs/article/guides/rails_integration_with_null_driver # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ video_dir = '/tmp/rails-system-test-videos' config.before :all, type: :system do FileUtils.rm_rf(video_dir) FileUtils.mkdir(video_dir) end class CapybaraNullDriver < Capybara::Driver::Base def needs_server? true end end Capybara.register_driver(:null) { CapybaraNullDriver.new } config.around(driver: :null) do |example| driven_by :null Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright| playwright.chromium.launch(headless: true) do |browser| browser.new_context( record_video_dir: video_dir, baseURL: Capybara.current_session.server.base_url ) do |context| # for requests this timeout can be too short, but for most steps it should be good # You can increase this in every selector on the test context.set_default_timeout(1500.0) @page = context.new_page # custom login process page.goto('/login-page', timeout: 50000) # first load may last longer ... example.run end if passed? FileUtils.rm(page.video.path) else puts "file://#{page.video.path}" end end end end end
和测试:
require 'playwright_helper' RSpec.describe "pw", type: :system, driver: :null do let(:page) { @page } it 'test' do page.goto('/') end end
概述
以上是系统测试的详细内容。更多信息请关注PHP中文网其他相关文章!