Running browser tests on Heroku without GUI

Hey everyone,

I’m trying to figure out how to run our browser tests on Heroku without a graphical interface. We’ve got a script that uses Selenium with Firefox, but it opens a visible browser window. I’m wondering if there’s a way to make it work headlessly on Heroku without changing too much of our existing code.

Has anyone done this before? I’m looking for tips on browser options or configurations that might help. It would be great if we could keep most of our current setup intact.

Any advice would be really appreciated. Thanks in advance!

P.S. If you’ve used a different approach altogether for this kind of testing on Heroku, I’d love to hear about that too.

For running browser tests on Heroku without a GUI, I’d recommend using Chrome in headless mode with Selenium WebDriver. It’s been quite reliable in my experience. You’ll need to update your script to use ChromeOptions and set the headless flag:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument(‘–headless’)
chrome_options.add_argument(‘–disable-gpu’)
driver = webdriver.Chrome(options=chrome_options)

This approach should work well on Heroku with minimal changes to your existing code. Remember to add the necessary buildpacks for Chrome and ChromeDriver. You might also need to set the GOOGLE_CHROME_BIN and CHROMEDRIVER_PATH environment variables in your Heroku config.

Just be aware that some tests might behave slightly differently in headless mode, so thorough testing is crucial.

hey there! have u tried using xvfb (X Virtual Framebuffer)? it lets u run GUI apps without an actual display. just wrap ur selenium commands with xvfb-run. might need to install xvfb on heroku tho. it worked gr8 for me without changing much code. good luck!

I’ve been in a similar situation, and I can tell you that running headless browser tests on Heroku is definitely doable. What worked for me was using Firefox in headless mode with Selenium WebDriver. You’ll need to adjust your script slightly, but it’s not a major overhaul.

First, make sure you’re using the latest geckodriver and Selenium versions. Then, modify your Firefox options to run headless:

from selenium.webdriver.firefox.options import Options

options = Options()
options.add_argument(‘-headless’)
driver = webdriver.Firefox(options=options)

This should allow your tests to run without a GUI. You might also need to set a few environment variables on Heroku, like GECKODRIVER_PATH and FIREFOX_BIN.

One caveat: some tests might behave differently in headless mode, so be prepared to debug a bit. But overall, this approach let me keep most of my existing code intact while running tests smoothly on Heroku.