我正在尝试使用Selenium docker运行我的测试,
我有一个在端口9000上运行的本地grunt服务器,我发起了以下selenium docker:
docker run -d -p 4444:4444 -p 5900:5900 selenium/standalone-chrome-debug
然后我启动了我的测试(使用Capybara)并打开VNC观看测试,但我得到的只是chrome messgae“这个网站无法到达”.
cabybara.rb:
isWindows = (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
require 'capybara/rspec'
require 'capybara'
require 'capybara/dsl'
require_relative 'sinatra_proxy'
require 'selenium/webdriver'
require 'selenium/webdriver/remote/http/curb' if !isWindows
Capybara.register_driver :selenium_chrome do |app|
http_client = isWindows ? nil : Selenium::WebDriver::Remote::Http::Curb.new
options = {
http_client: http_client,browser: :chrome,# service_log_path: 'chromedriver.out',# Enable Selenium logs
switches: ["--disable-web-security",'--user-agent="Chrome under Selenium for Capybara"']
}
options[:url] = "http://172.17.0.2:4444/wd/hub"
Capybara::Selenium::Driver.new app,options
end
Capybara.default_driver = :selenium_chrome
Capybara.app = SinatraProxy.new
Capybara.app_host = "http://127.0.0.1:9000"
Capybara.server_host = '0.0.0.0'
ip addr show docker0
ip addr show docker0
6: docker0:
需要是docker主机的IP,用于:
ip route show | grep docker0 | awk '{print $9}'
for Capybara.app_host(DOCKER_HOST_IP:PORT)和Capybara.server_host(DOCKER_HOST_IP)
最佳答案