Capybara headless chrome in docker returns DevToolsActivePort file doesn't exist

前端 未结 1 1031
醉酒成梦
醉酒成梦 2021-02-18 23:06

Im trying to configure system tests to work with headless chrome in selenium. I have the following capybara configuration:

# spec/support/capybara.rb

Capybara.s         


        
1条回答
  •  爱一瞬间的悲伤
    2021-02-18 23:23

    It seems like the default selenium_chrome_headless settings of capybara aren't sufficient for running in a docker container. I have solved it by changing my spec/support/capybara.rb settings to the following:

    # spec/support/capybara.rb
    
    # Setup chrome headless driver
    Capybara.server = :puma, { Silent: true }
    
    Capybara.register_driver :chrome_headless do |app|
      options = ::Selenium::WebDriver::Chrome::Options.new
    
      options.add_argument('--headless')
      options.add_argument('--no-sandbox')
      options.add_argument('--disable-dev-shm-usage')
      options.add_argument('--window-size=1400,1400')
    
      Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
    end
    
    Capybara.javascript_driver = :chrome_headless
    
    # Setup rspec
    RSpec.configure do |config|
      config.before(:each, type: :system) do
        driven_by :rack_test
      end
    
      config.before(:each, type: :system, js: true) do
        driven_by :chrome_headless
      end
    end
    

    Especially "--disable-dev-shm-usage" should not be forgotten, as it solves limited resource problems in docker, as noted in: https://github.com/GoogleChrome/puppeteer/issues/1834

    Edit: I haven't made any changes to the above Dockerfile

    0 讨论(0)
提交回复
热议问题