1

I cannot find anything that shows the right way to pass in capabilities and create a remote session. something like the below

Capybara.default_driver = :Selenium
@session = Capybara::Session.new :selenium

Could anyone point me in the right direction on how to do this? I have seen numerous examples of how to register a remote like this https://blog.testingbot.com/2012/02/19/selenium-cucumber-capybara, but nothing to get the instance of it so that I can act on it in the code.

hhcib
  • 193
  • 2
  • 2
  • 15

2 Answers2

1
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

Now, :remote_chrome driver will be used when you try to start a new session by calling Capybara.page method.

0

assuming you have registered the driver like in the article you listed then to create a session its just like you put in your question

session = Capybara::Session.new :registered_driver_name

If you want capybara to run the app under test itself then its

session = Capybara::Session.new :registered_driver_name, rack_app
Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78