teamcapybara / capybara

Acceptance test framework for web applications
http://teamcapybara.github.io/capybara/
MIT License
10.03k stars 1.45k forks source link

Capybara cannot configure Firefox #2766

Open adeherdt-r7 opened 4 months ago

adeherdt-r7 commented 4 months ago

Meta

Capybara Version: 3.40.0 Driver Information (and browser if relevant):

Expected Behavior

Actual Behavior

Tests crash during Capybara configuration:

Selenium::WebDriver::Error::UnknownError: Process unexpectedly closed with status 127
/home/noel/.rvm/gems/ruby-3.1.4@pro/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/response.rb:55:in `assert_ok'
/home/noel/.rvm/gems/ruby-3.1.4@pro/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/response.rb:34:in `initialize'
/home/noel/.rvm/gems/ruby-3.1.4@pro/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/http/common.rb:83:in `new'
/home/noel/.rvm/gems/ruby-3.1.4@pro/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/http/common.rb:83:in `create_response'
/home/noel/.rvm/gems/ruby-3.1.4@pro/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/http/default.rb:104:in `request'
/home/noel/.rvm/gems/ruby-3.1.4@pro/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
/home/noel/.rvm/gems/ruby-3.1.4@pro/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/bridge.rb:620:in `execute'
/home/noel/.rvm/gems/ruby-3.1.4@pro/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/remote/bridge.rb:53:in `create_session'
/home/noel/.rvm/gems/ruby-3.1.4@pro/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/common/driver.rb:317:in `block in create_bridge'
<internal:kernel>:90:in `tap'
/home/noel/.rvm/gems/ruby-3.1.4@pro/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/common/driver.rb:316:in `create_bridge'
/home/noel/.rvm/gems/ruby-3.1.4@pro/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/common/driver.rb:74:in `initialize'
/home/noel/.rvm/gems/ruby-3.1.4@pro/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/firefox/driver.rb:43:in `initialize'
/home/noel/.rvm/gems/ruby-3.1.4@pro/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/common/driver.rb:53:in `new'
/home/noel/.rvm/gems/ruby-3.1.4@pro/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver/common/driver.rb:53:in `for'
/home/noel/.rvm/gems/ruby-3.1.4@pro/gems/selenium-webdriver-4.10.0/lib/selenium/webdriver.rb:88:in `for'
/home/noel/.rvm/gems/ruby-3.1.4@pro/gems/capybara-3.40.0/lib/capybara/selenium/driver.rb:75:in `browser'
/home/noel/RubymineProjects/pro/ui/features/support/hooks/browser.rb:3:in `Before'

The before block:

Before('not @json') do
  Capybara.reset_sessions!
  Capybara.current_session.driver.browser.manage.window.resize_to(1920, 1050)
  if TestConfig.instance.video_capture
    TestConfig.instance.headless.video.start_capture
  end
end

Steps to reproduce

twalpole commented 2 months ago

Seems like you're trying to set the window size on a non-existent session

adeherdt-r7 commented 2 months ago

Seems like you're trying to set the window size on a non-existent session

The issue is snap. This is Firefox installed through snap, and Capybara is unable to work with it. Standalone installations seem to work fine.

bogn83 commented 3 days ago

I tried the different combinations that snap installs since /usr/bin/firefox is just a wrapper to start these with snap:

/snap/bin/firefox
/snap/bin/firefox.geckodriver
/snap/bin/geckodriver

The only one that worked to get past the not a firefox binary error was '/snap/bin/firefox'

options = Selenium::WebDriver::Firefox::Options.new
options.binary = '/snap/bin/firefox'
service = Selenium::WebDriver::Service.firefox
service.executable_path = options.binary
puts "!!! #{`ls -l #{options.binary}`}"
driver = Selenium::WebDriver.for :firefox, service: service, options: options
Capybara.current_driver = driver

While this gets me past the binary path not found errors and opens a firefox, I still get:

Selenium::WebDriver::Error::WebDriverError:
  unable to connect to /snap/bin/firefox 127.0.0.1:4507