概述
它比 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中文網其他相關文章!