Question: How to run capybara tests on existing session with `debuggerAddress`

Question

How to run capybara tests on existing session with `debuggerAddress`

Answers 0
Added at 2017-07-30 19:07
Tags
Question

original issue here (maybe someone know answer)

I want to use capybara-rspec tests in existing session of chrome (no external chrome, use my chrome, just open new tab and run tests, then close tab) I have found that this is feasible using debuggerAddress

How to do it without capy

// close all chrome windows
$ google-chrome-stable --remote-debugging-port=4444
// chrome opened with my profile
$ pry
>  require 'selenium-webdriver'
>  options = Selenium::WebDriver::Chrome::Options.new
>  options.add_option('debuggerAddress', '127.0.0.1:4444')
>  driver = Selenium::WebDriver.for :chrome, options: options
.... currently opened page is driver.current_url

Steps to reproduce

// spec/config

# usage - close chrome and 'google-chrome-stable --remote-debugging-port=4444'
require 'selenium-webdriver'

Capybara.register_driver :local_chrome do |app|
  options = Selenium::WebDriver::Chrome::Options.new
  options.add_option('debuggerAddress', '127.0.0.1:4444')

  Capybara::Selenium::Driver.new(app,
                                  browser: :chrome,
                                  options: options)
end

Capybara.javascript_driver = :local_chrome
Capybara.default_driver    = :local_chrome

server_port = ENV['PORT']              # port of rails api 
client_port = ENV['CLIENT_PORT'] # port of my spa, I want test to 

if !server_port || !client_port
  puts 'Warning: No PORT' unless server_port
  puts 'Warning: No CLIENT_PORT' unless client_port
  puts 'Feature tests will probably fail'
else
  Capybara.server_port = server_port
  Capybara.app_host = "http://localhost:#{client_port}"
end

then in some feature test visit('/') or current_url is causing infinite loading

Answers to

How to run capybara tests on existing session with `debuggerAddress`

Source Show
◀ Wstecz