繁体   English   中英

带有硒/独立铬的dockerized Rails 5应用中RSpec系统测试的SSL错误

[英]SSL Error on RSpec system tests in dockerized Rails 5 app with selenium/standalone-chrome

来自Rails 3,从没使用过Capybara / Selenium我现在在docker中运行Rails 5应用程序,想要使用“更新的”编写测试的方式,即使用系统,请求和模型规格而不是控制器规格。 我添加了另一个与Guard运行同一映像的docker实例,以在发生任何更改时触发相应的测试。 由于RSpecs系统测试需要Selenium,因此我正在为docker运行官方的selenium/standalone-chrome映像。 一切似乎都已完美插入,但是系统测试失败,因为Selenium似乎正在尝试使用SSL。 如果我明确要求使用http,为什么会这样? 有什么办法可以关闭它吗?

我正在使用docker-compose来启动和运行所有程序,而docker-compose.yml的重要部分是:

version: '3.5'

services:

  app:
    build: .
    volumes:
      - .:/srv/mldb
    ports:
      - "3000:3000"
    depends_on:
      - db
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    tty: true

  guard:
    build: .
    volumes:
      - .:/srv/mldb
    depends_on:
      - app
      - chrome
    command: bundle exec guard --no-bundler-warning --no-interactions
    tty: true
  chrome:
    image: selenium/standalone-chrome
    volumes:
      - /dev/shm:/dev/shm
    ports:
      - "4444:4444"

这是我用来设置水豚和硒的spec/rails_helper.rb中所有相关的行:

selenium_url = "http://chrome:4444/wd/hub"

Capybara.register_driver :selenium_remote do |app|
  Capybara::Selenium::Driver.new(
    app,
    browser: :remote,
    url: selenium_url,
    desired_capabilities: :chrome)
end

RSpec.configure do |config| 
  config.before(:each, type: :system, js: true) do
    driven_by :selenium_remote
    host! "http://app:3000"
  end
end

我在运行示例测试时遇到的错误只是尝试填写输入字段,然后按提交按钮。

从运行系统规范的Guard容器中:

1) Movie management given correct input values allows user to create movie
    Capybara::ElementNotFound:
       Unable to find button "New Movie"

从应用程序容器运行轨道:

2019-04-06 16:28:22 +0000: HTTP parse error, malformed request (): #<Puma::HttpParserError: Invalid HTTP format, parsing fails.>

日志文件的内容:

   (0.4ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
   (0.2ms)  BEGIN
   (0.2ms)  ROLLBACK

水豚拍摄的屏幕截图:

错误

所有其他测试(请求和模型规格)均运行良好,手动进行的所有测试也均正常运行。

这是失败的系统规格:

require 'rails_helper'                                                                                

RSpec.describe "Movie management", type: :system, js: true do                                         

  context "given correct input values" do                                                             

    it "enables users to create movies" do                                                            
      visit "/movies"                                                                                 
      expect(page).to_not have_text("Hellboy")                                                        

      click_button "New Movie"                                                                        

      fill_in "Titel", with: "Hellboy"                                                                
      fill_in "Jahr", with: "2004"                                                                    

      click_button "Film anlegen"                                                                     

      expect(page).to have_current_path("/movies")                                                    
      expect(page).to have_text("Film erfolgreich angelegt.")                                         
      expect(page).to have_text("Hellboy")                                                            
      expect(page).to have_text("2004")                                                               
    end                                                                                               
  end                                                                                                 
end                        

问题是Google拥有TLDs app并强制浏览器使用HTTPS。 这是关于它的链接。

https://superuser.com/questions/1276048/starting-with-chrome-63-urls- contains-app-redirects-to-https

解决方案是不要将app用作您网站的容器名称。 当使用website名称作为我的网站容器时,我的测试运行良好。

此链接中有关Google TLD的更多信息

https://chromium.googlesource.com/chromium/src/net/+/master/http/transport_security_state_static.json#285

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM