Error in Selenium-Webdriver when running headless automated system tests against Rails 7 app on Heroku slug

159 Views Asked by At

My system tests run fine locally and also as a GitHub Action but fail when I try to run on a test server deployed using Heroku. It fails with the following error:

-----> Running test command `bin/rails test:system`...
Chrome Shim ENV variable:
/app/.apt/usr/bin/google-chrome-stable
Run options: --seed 1107
# Running:
loading test data
E
Error:
UserStory6Test#test_modify_an_existing_comment_to_an_empty_string:
Selenium::WebDriver::Error::SessionNotCreatedError: session not created: Chrome failed to start: exited normally.
 (session not created: DevToolsActivePort file doesn't exist)
 (The process started from chrome location /app/.cache/selenium/chrome/linux64/117.0.5938.149/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

I followed the available heroku documentation I could find by adding the following to my test_helper.rb:

  #This code to provide correct path to the chrome library on heroku test environment
  chrome_bin = ENV.fetch('GOOGLE_CHROME_SHIM', nil)

  chrome_opts = chrome_bin ? { "chromeOptions" => { "binary" => chrome_bin } } : {}

  Capybara.register_driver :chrome do |app|
    Capybara::Selenium::Driver.new(
      app,
      browser: :chrome,
      desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(chrome_opts)
    )
  end

Capybara.javascript_driver = :chrome

and this app.json file:

{
    "buildpacks": [
      { "url": "heroku/ruby" },
      { "url": "heroku/chromedriver" },
      { "url": "heroku/google-chrome" }
    ],

    "environments": {
        "test": {
          "addons": ["heroku-postgresql:in-dyno"],
          "scripts": {
            "test": "bin/rails test:system"
          }
        }
      }
}

Here are some related info from the Heroku test setup log:

-----> Fetching heroku/chromedriver buildpack...
      buildpack downloaded
-----> Fetching heroku/google-chrome buildpack...
      buildpack downloaded
...
Using selenium-webdriver 4.11.0
...
-----> chromedriver app detected
-----> Looking up latest chromedriver version...
-----> Downloading chromedriver v117.0.5938.149...
Archive:  /tmp/chromedriver.zip
 inflating: /app/.chromedriver/bin/LICENSE.chromedriver 
 inflating: /app/.chromedriver/bin/chromedriver 
-----> Creating chromedriver export scripts...
-----> Google Chrome app detected
-----> Installing Google Chrome from the stable channel.
...
-----> Creating google-chrome shims

Here are some related info from the Heroku test-run log:

-----> Running test command `bin/rails test:system`...
Chrome Shim ENV variable: 
/app/.apt/usr/bin/google-chrome-stable
Run options: --seed 1107
# Running:
loading test data
E
Error:
UserStory6Test#test_modify_an_existing_comment_to_an_empty_string:
Selenium::WebDriver::Error::SessionNotCreatedError: session not created: Chrome failed to start: exited normally.
  (session not created: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /app/.cache/selenium/chrome/linux64/117.0.5938.149/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
    test/system/user_story_6_test.rb:53:in `block in <class:UserStory6Test>'
Error:
UserStory6Test#test_modify_an_existing_comment_to_an_empty_string:
Selenium::WebDriver::Error::SessionNotCreatedError: session not created: Chrome failed to start: exited normally.
  (session not created: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /app/.cache/selenium/chrome/linux64/117.0.5938.149/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
    #0 0x5653a7a39933 <unknown>
    #1 0x5653a77136f7 <unknown>
    #2 0x5653a7746a55 <unknown>
    #3 0x5653a7742bbc <unknown>
    #4 0x5653a778577a <unknown>
    #5 0x5653a777c3d3 <unknown>
    #6 0x5653a774ee64 <unknown>
    #7 0x5653a774fc4e <unknown>
    #8 0x5653a79ff558 <unknown>
    #9 0x5653a7a034a0 <unknown>
    #10 0x5653a7a0d97c <unknown>
    #11 0x5653a7a040b8 <unknown>
    #12 0x5653a79cfcdf <unknown>
    #13 0x5653a7a28048 <unknown>
    #14 0x5653a7a28219 <unknown>
    #15 0x5653a7a38ac3 <unknown>
    #16 0x7fed2cefeb43 <unknown>
    /app/vendor/bundle/ruby/3.1.0/gems/selenium-webdriver-4.11.0/lib/selenium/webdriver/remote/response.rb:55:in `assert_ok'
0

There are 0 best solutions below