A lot of people using the Selenium framework to automate interaction with a browser. It supports major browsers, Chrome, Firefox, Safari, etc.

But sometimes it's quite annoying that to run some of your automation you need to have a separate computer with a desktop environment. Basically, whenever you want to run some scenario, selenium will open a browser and execute the script.

Headless Browsers

There are some ways to avoid that, the first one is by using PhantomJS as a web driver, unfortunately, this project is not supported anymore.

The other solution is to use Pupeteer, nodejs library to control headless Chrome or Chromium, but in this case, you are limited with only one browser and you need to review all scenarios. Not the best solution.

For Firefox and Chrome, you can use --headless command-line argument, but in this case, you first need to configure each web driver and not all of them support this mode. This is a good option if you need cross-platform support since the next solution will only work on Linux.

Xvfb

Xvfb is a display server implementing the X11 display server protocol. This program will allow you to run any application in a "headless" mode. Basically, instead of outputting GUI on a physical screen, this program will create a virtual framebuffer and "display" UI there.

To install it, execute the following:

sudo apt-get install xvfb

The simplest way to use this program is to run any command that needs a screen via xvfb-run command.

xvfb-run ./Runner

In this case, Runner is a console application that uses Selenium to run automated test scenarios in Firefox and Chrome.

This is how you can make any GUI application headless.