首页 > web前端 > js教程 > 系统测试

系统测试

DDD
发布: 2024-12-18 13:00:17
原创
539 人浏览过

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
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板