require 'capybara'
require 'selenium-webdriver'
#Register driver
WEBDRIVER_HUB_URL = "http://<YOUR_SELENIUM_GRID_HOST>:4444/wd/hub"
TARGET_RESOLUTION = [1280,1024]
CHROME_SWITCHES = %W(--window-size=#{TARGET_RESOLUTION[0]},#{TARGET_RESOLUTION[1]} --disable-translate)
CHROME_OPTIONS = {
'args' => CHROME_SWITCHES
}
Capybara.register_driver :remote_chrome do |app|
caps = Selenium::WebDriver::Remote::Capabilities.chrome(:chromeOptions => CHROME_OPTIONS)
opts = {
:browser => :remote,
:url => WEBDRIVER_HUB_URL,
:desired_capabilities => caps
}
Capybara::Selenium::Driver.new(app, opts)
end
# Configure Capybara
Capybara.configure do |config|
config.default_driver = :remote_chrome
config.javascript_driver = :remote_chrome
end
現在,當您試圖通過調用Capybara.page
方法來啓動一個新的會話:remote_chrome
驅動程序將被使用。