簡體   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