Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Steps in README do not work on a new created app #12

Open
alebian opened this issue Oct 27, 2020 · 2 comments
Open

Steps in README do not work on a new created app #12

alebian opened this issue Oct 27, 2020 · 2 comments

Comments

@alebian
Copy link

alebian commented Oct 27, 2020

Hi! I recently created a new app in Heroku, installed the buildpack, added the ENV variables and it is not working.

I tried different things commented on other issues (I'm using Ruby):

Selenium::WebDriver::Firefox::Binary.path = ENV['FIREFOX_BIN']
Selenium::WebDriver::Firefox.driver_path = ENV['GECKODRIVER_PATH']
options = Selenium::WebDriver::Firefox::Options.new(args: ['-headless', '--disable-gpu', '--no-sandbox', '--remote-debugging-port=9224'])
browser = Selenium::WebDriver.for(:firefox, options: options)

But I'm getting

Selenium::WebDriver::Error::SessionNotCreatedError (Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line)

My env variables are:

FIREFOX_BIN=/app/vendor/firefox/firefox
GECKODRIVER_PATH=/app/vendor/geckodriver/geckodriver
LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib:/app/vendor
PATH=/usr/local/bin:/usr/bin:/bin:/app/vendor/

I also tried removing the buildpack from the heroku webapp, installing it from the command line and restarting the dynos (as commented #3 (comment) but it didn't work)

Thanks!

@pyronlaboratory
Copy link
Owner

Hello alebian, looks like you're using a deprecated method for setting the path to your Geckodriver.

This is how I bootstrap a ruby app for using selenium

#!/usr/bin/env ruby
 
require 'bundler/setup'
Bundler.require
 
require "selenium-webdriver" 

Selenium::WebDriver::Firefox::Binary.path = "/app/vendor/firefox/firefox" #your heroku env variables should reflect this path
puts "Binary file located at: #{Selenium::WebDriver::Firefox::Binary.path}"

Selenium::WebDriver::Firefox::Service.driver_path = "/app/vendor/geckodriver/geckodriver" #your heroku env variables should reflect this path
puts "Geckodriver located at: #{Selenium::WebDriver::Firefox::Service.driver_path}"

Selenium::WebDriver.logger.level = :debug

options = Selenium::WebDriver::Firefox::Options.new(args: ['-headless', '--disable-gpu', '--no-sandbox', '--remote-debugging-port=9224'])
 
driver = Selenium::WebDriver.for(:firefox, options: options)

driver.get "http://google.com"
puts "Driver discovered webapp: #{driver.title}"
driver.quit

Do post a detailed debug log if you're still facing the error.

@pdobb
Copy link

pdobb commented Mar 20, 2022

Note:

Selenium::WebDriver::Firefox::Binary.path = "..."

Should (now) be:

Selenium::WebDriver::Firefox.path = "..."

in selenium-webdriver v4.1.0.

Otherwise, this worked for me, thanks @pyronlaboratory.

The problem I've been having is when/where to set these paths in a Rails app. But just running your code in the rails console does work.

UPDATE: A solution that worked for my case is to do this in a Rails initializer file:

# Use `:debug` instead of `:info` for detailed logs in case of an error.
Selenium::WebDriver.logger.level = :warn

if Rails.env.development?
  Capybara.default_driver = :selenium
else # Production
  # Heroku-specific setup for Selenium + Firefox paths, etc.

  Capybara.default_driver = :selenium_headless

  if File.exist?(ENV["FIREFOX_BIN"])
    Selenium::WebDriver::Firefox.path = ENV["FIREFOX_BIN"]
    Selenium::WebDriver::Firefox::Service.driver_path = ENV["GECKODRIVER_PATH"]
  end
end

The key part being if File.exist?(ENV["FIREFOX_BIN"]). This conditional allows the deploys to work without fail, and also is what's needed when running the Rails application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants