Running browser automation tests without GUI on Heroku platform

I’m looking for advice on implementing browser automation tests that don’t show a visual interface on Heroku. My team created a test script that uses Selenium to control Firefox, and currently it opens the actual browser window during execution.

The problem is that our current setup won’t work on Heroku since there’s no display available. I need to modify our existing code to run the same tests but without showing the browser interface.

What configuration options or browser settings should I use to make this work? I want to keep our current code structure as much as possible and just add the necessary headless configurations.

Any suggestions on the best approach for this would be really helpful.

Switching to headless mode with Firefox and Selenium is straightforward. I faced a similar issue when deploying to a cloud service. To fix this, simply add the headless option to your FirefoxOptions prior to initializing the WebDriver. First, create a FirefoxOptions object and include the headless flag using the addArguments method, then pass this object to your WebDriver constructor. Additionally, including the disable-gpu and no-sandbox arguments might enhance compatibility with Heroku. Your tests will perform identically, minus the browser window. However, do test locally in headless mode first, as some tests might behave unexpectedly with viewport or JavaScript features.

I hit this exact issue migrating our test suite to Heroku six months back. Main thing that’s different from what’s already mentioned - you need the heroku-buildpack-google-chrome buildpack even if you’re running Firefox. It handles the display dependencies that’ll break otherwise. Set your window size explicitly in the browser options too. Headless browsers default to tiny dimensions and will mess up responsive tests. Heroku’s filesystem resets between runs, so any file downloads or operations need tweaking. Found that out when our screenshot tests just stopped working with zero errors.

Just dealt with this last week on our selenium setup. Firefox headless runs solid, but memory usage will kill you on Heroku - kept hitting limits until I threw in the --memory-pressure-off flag. Make sure you’re actually closing those webdriver instances too, or they’ll stack up and crash your dynos.