Running browser automation without GUI on Heroku deployment

I’m trying to figure out how to run automated browser tests on Heroku without displaying the actual browser window. My team has created a testing script that uses Selenium to control Firefox, and it works great on our local machines where we can see the browser opening and running the tests.

The problem is that when we deploy to Heroku, there’s no display available so our current setup fails. I’ve heard about headless mode but I’m not sure how to implement it. Is there a way to modify our existing Selenium configuration to run in headless mode without rewriting everything?

I’m looking for the simplest approach to make our Firefox automation work on Heroku’s environment. Any configuration options or code adjustments that could help would be really appreciated. We want to keep our current test logic but just need it to run without the GUI.

Converting to headless mode is pretty straightforward. I hit this same issue deploying to Heroku last year - way simpler fix than I thought. Just add headless options to your Firefox driver before you initialize it. Create a FirefoxOptions object, call add_argument with ‘–headless’, then pass those options when creating your WebDriver. Also throw in ‘–no-sandbox’ and ‘–disable-dev-shm-usage’ for better Heroku compatibility. Don’t forget the geckodriver buildpack on Heroku. Your test logic stays exactly the same - you’re only changing driver initialization. Worked great for our CI pipeline, plus headless tests run way faster anyway.

Running headless on Heroku isn’t just about browser config. I spent hours debugging this when our deployment kept crashing even with proper headless setup. Heroku’s dyno filesystem has specific requirements for browser automation. You need Firefox to use /tmp for profiles and cache since Heroku’s filesystem is read-only except temp folders. Set your Firefox profile path explicitly and disable GPU with --disable-gpu. Also bump up your timeout values - Heroku dynos are slower than local machines. Double-check your buildpack versions. Mismatched geckodriver and Firefox versions cause silent failures that are a pain to debug. Test locally with the same versions you’ll have on Heroku first.

Heroku’s a pain with Selenium. Set DISPLAY=:99 in your Procfile even when running headless - that fixed it for me. Make sure Firefox buildpack comes before Python in your buildpack order. Watch your memory too - Firefox chews through RAM on Heroku. Try smaller dynos for testing or throw in some delays between actions.