Ikhtisar
Ia lebih pantas dan lebih baharu daripada Selenium dan mempunyai sintaks yang lebih jelas daripada Capybara-DSL, lihat Perbincangan.
Perhatian Penulis drama boleh digunakan dengan Capybara DSL, yang boleh dikatakan bagus untuk projek sedia ada. Tetapi, sekurang-kurangnya dalam ujian saya, ia tidak mungkin untuk mengkonfigurasinya supaya spesifikasi sedia ada yang ditulis dalam Capybara-DSL boleh berterusan. Saya terpaksa menulis semula.
Diperoleh daripada Dokumen
Persediaan
Fail seperti 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
dan ujian:
require 'playwright_helper' RSpec.describe "pw", type: :system, driver: :null do let(:page) { @page } it 'test' do page.goto('/') end end
Ikhtisar
Atas ialah kandungan terperinci Pengujian Sistem. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!