I am BARRY HESS > Blog

Rails System Tests with Safari

Not gonna bury the lede. Did you know you can write Rails system tests against Safari? I think most of the documentation and old websites that come up on search largely talk about Chrome and Firefox, but Safari is on the table:

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :selenium, using: :safari, screen_size: [1400, 1400],

When you first run your system tests with that setup, you will get an error:

Selenium::WebDriver::Error::SessionNotCreatedError:
Could not create a session: You must enable the 'Allow Remote
Automation' option in Safari's Develop menu to control Safari
via WebDriver.

So go do that in Safari > Develop > Allow Remote Automation. Then you'll find a browser pop up and do things when you run your tests.

Honestly, I couldn't handle that as my default flow. I wanted headless. I don't have Chrome installed because Google. I generally use Firefox Developer Edition, but I couldn't figure out the magic incantation to make use of it as my Firefox driver. I tried this:

driven_by :selenium, using: :headless_firefox, screen_size: [1400, 1400],
  options: { driver_path: "/Applications/Firefox Developer Edition.app" }

But unfortunately:

Selenium::WebDriver::Error::WebDriverError: not a file:
"/Applications/Firefox Developer Edition.app"

So I gave in, installed Firefox, and called it a day:

driven_by :selenium, using: :headless_firefox, screen_size: [1400, 1400]