mavenselenium-webdriverjenkinsheadless-browserxserver

Implementing Selenium tests automation via Jenkins for Maven project


I am trying to integrate selenium tests suite (Maven) with jenkins and I am using chrome headless browser but facing error as below.

[2114:2114:0905/122912.875011:ERROR:ozone_platform_x11.cc(239)] Missing X server or $DISPLAY
[2114:2114:0905/122912.875064:ERROR:env.cc(255)] The platform failed to initialize.  Exiting.
Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.

The chrome driver and google binaries installed are same.

Below code has been implemented inside Drivermodule.java file for headless browser.

System.setProperty("webdriver.chrome.driver", "/usr/bin/google-chrome");
ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
driver = new ChromeDriver(options);
driver.get("https://www.google.com");

I am using Amazon Linux 2 server for running jenkins node.


Solution

  • "webdriver.chrome.driver", "/usr/bin/google-chrome"
    

    In the above line, it looks like you are setting the browser path and not driver's path.

    You need to download the chromedriver for linux and set the path of it as below:

    "webdriver.chrome.driver","/usr/bin/chromedriver"