Update: added java code running Chrome in headless mode.
You can see these videos on this topic examples here:

Problem

If you want to run headless test in Ubuntu 16.04 you can do this by installing latest available version of Chrome. Then all you need to do is to run the browser with good settings.

Solution Install Google Chrome on Ubuntu 16.04 GUI

  • Go to https://www.google.com/chrome
  • Click the Download Chrome button.
  • Choose your version and accept - 64 bit .deb for Mint/Ubuntu
  • Open it by Ubuntu Software
  • Click the Install button to install google-chrome-stable
  • Enter your password
  • start by google-chrome-stable

Installation is straightforward and can be done with several commands:

sudo apt-get update
sudo apt-get install -y libappindicator1 fonts-liberation
cd /temp
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb

Solution Install Google Chrome on Ubuntu 16.04 Quick

If you you just want quick chrome installation you can do it by:

cd temp
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i --force-depends google-chrome-stable_current_amd64.deb
sudo apt-get install -f

Solution Install Google Chrome on Ubuntu 16.04 no GUI

Installation is straightforward and can be done with several commands:

sudo apt-get update
sudo apt-get install -y libappindicator1 fonts-liberation
cd temp
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb

This is going to install dependencies required for chrome to be installed.

In case of error related to unmet dependencies you can do:

sudo apt-get -f install
sudo dpkg --configure -a

As last option you can try with:

sudo apt-get -u dist-upgrade

and then to try to installed it again.

Other optional dependencies :

sudo apt-get -y install dbus-x11 xfonts-base xfonts-100dpi xfonts-75dpi xfonts-cyrillic xfonts-scalable

More info about chrome installation

If you like to have script which is preparing and installing all required libraries you can check here:

Install Chrome, ChromeDriver and Selenium on Ubuntu 16.04

Install Chrome, ChromeDriver and Selenium

Test installation version

Verify the version and is it install by

google-chrome-stable -version

If you want to test work in headless mode you can do:

google-chrome-stable --headless --disable-gpu --dump-dom https://www.chromestatus.com/

and check the output picture

or simply by checking for running process:

ps aux | grep chrome

If you want to print PDF or take screenshot in headless mode:

google-chrome-stable --headless --disable-gpu --print-to-pdf https://www.chromestatus.com/
google-chrome-stable --headless --disable-gpu --screenshot https://www.chromestatus.com/

Note: in some cases you may need to run:

chrome --headless --disable-gpu --dump-dom https://www.chromestatus.com/

Execute headless test with Java, Chrome and Selenium

Simple test with java 8, Selenium 3.5.3 and ChromeDriver to run chrome in headless mode:

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class Test {

    public static void main(String[] args) {

        //set chrome driver, headless mode
        String driverPath = "/home/guest/chromedriver";
        System.setProperty("webdriver.chrome.driver", driverPath);
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--headless");

        //create new driver
        ChromeDriver driver = new ChromeDriver(options);

        //get google page and print title
        String page = "http://google.com";
        driver.get(page);
        System.out.println( "Title of the page is -> " + driver.getTitle());

        // find the search edit box on the google page
        WebElement searchBox = driver.findElement(By.name("q"));

        // type in Selenium - Softhints
        searchBox.sendKeys("Softhints");
        searchBox.submit();

        //verify the new page title
        System.out.println( "Title of the page is -> " + driver.getTitle());

        driver.close();
        driver.quit();
    }

}

Execute headless test with Groovy, Chrome and Selenium

This is simple groovy code which is doing headless test on Ubuntu Server using Selenium 3.5.3 and ChromeDriver. In order to use it you need to download web driver by:

mkdir driver
wget https://chromedriver.storage.googleapis.com/2.35/chromedriver_linux64.zip
cd driver
unzip chromedriver_linux64.zip 

Next code open Google Chrome in headless mode on Ubuntu Server. Open page google.com and print the title. Then search for Softhints and print the title.

@Grab("org.seleniumhq.selenium:selenium-chrome-driver:3.5.3")
@Grab("org.seleniumhq.selenium:selenium-support:3.5.3")

import org.openqa.selenium.By
import org.openqa.selenium.WebElement
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions

def driverPath = ""

driverPath = /\/home\/user\/driver\/chromedriver/
System.setProperty("webdriver.chrome.driver", driverPath);
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");


ChromeDriver driver = new ChromeDriver(options);

def page = "http://google.com"

        driver.get(page)

        println "Title of the page is -> " + driver.getTitle()

        // find the search edit box on the google page
        WebElement searchBox = driver.findElement(By.name("q"))

        // type in Selenium
        searchBox.sendKeys("Softhints");

        // find the search button
        WebElement button = driver.findElement(By.name("btnK"))

        // Click the button
       button.click();

       println "Title of the page is -> " + driver.getTitle()

driver.close();
driver.quit();

the result of the execution is:

Starting ChromeDriver 2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881) on port 8528
Only local connections are allowed.
Jan 30, 2018 3:39:10 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Title of the page is -> Google

Title of the page is -> Softhints - Google ???????

Install groovy and Java

If you want to test this code on your server you can install Java and Groovy by:

sudo apt-get install default-jre
sudo apt-get install default-jdk
sudo apt-get install curl unzip zip
curl -s get.sdkman.io | bash
source "$HOME/.sdkman/bin/sdkman-init.sh" #or simply open new terminal
sdk install groovy
groovy -v

Test installation by groovy -v and the result should be:

Groovy Version: 2.4.13 JVM: 1.8.0_151 Vendor: Oracle Corporation OS: Linux