首頁 > web前端 > js教程 > 系統測試

系統測試

DDD
發布: 2024-12-18 13:00:17
原創
543 人瀏覽過

System Testing

概述

為什麼是劇作家?

它比 Selenium 更快、更新,並且比 Capybara-DSL 具有更清晰的語法,請參閱討論。

注意 Playwright 可以與 Capybara DSL 一起使用,這對於現有項目來說聽起來不錯。但是,至少在我的測試中,無法對其進行配置以使用 Capybara-DSL 編寫的現有規範得以保留。我不得不重寫它們。

Rails/RSpec 內的劇作家

源自文件

設定

  • 移除所有硒寶石
  • 在組別測試中加入寶石水豚
  • 在組別測試中加入 gem playwright-ruby-client
  • npm i --save-dev playwright (與文件不同,不要透過 npx i 安裝它......因為它不會安裝依賴項)

類似 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中文網其他相關文章!

來源:dev.to
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板