0
votes

I have been trying to run headless chrome on Ubuntu 16.04 LTS, have downloaded the latest Chrome Driver (2.32 for Linux x64) here is the code, I have written the following code:

package com.test.tests;

import static org.testng.Assert.assertTrue;

import java.io.IOException;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testng.annotations.Test;

public class ChromeHeadlessTest {

    @Test
    public void testExecution() throws IOException {
        System.setProperty("webdriver.chrome.driver", "resources/linux/chromedriver");

        // Add options to Google Chrome. The window-size is important for responsive sites
        ChromeOptions options = new ChromeOptions();
        options.addArguments("headless");
        options.addArguments("window-size=1200x600");

        WebDriver driver = new ChromeDriver(options);
        driver.get("https://google.co.in");

        // a guarantee that the test was really executed
        assertTrue(driver.findElement(By.id("hplogo")).isDisplayed());

        driver.quit();
    }
}

When I run this test as TestNG Test, I get the following error:

[RemoteTestNG] detected TestNG version 6.8.2
[TestNG] Running:
  /tmp/testng-eclipse-1039732738/testng-customsuite.xml

FAILED: testExecution
java.lang.NoClassDefFoundError: org/apache/commons/exec/ExecuteWatchdog
    at org.openqa.selenium.os.CommandLine.<init>(CommandLine.java:38)
    at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:176)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:78)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:184)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:171)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:158)
    at com.highq.test.tests.ChromeHeadlessTest.testExecution(ChromeHeadlessTest.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.exec.ExecuteWatchdog
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 35 more

I have searched a lot for the fix but could not.

Thanks in advance

3

3 Answers

0
votes

The problem is that your driver isn't initialized. From this line:

The driver executable does not exist: /usr/bin/chrominum-browser

First of all make sure that chromedriver.exe exists in the above folder.

If that is the case, then you can try a different initialization, like so:

driver = webdriver.Chrome(chrome_options=options);
0
votes

Here you have missed the commons-exec-1.3 jar file. Try to add the jar file it will works fine https://commons.apache.org/proper/commons-exec/download_exec.cgi

0
votes

1st Error

First of all your heading error is different which is related to Apache poi jar error which can be removed by below solution.

Adding commons-logging.jar should solve this type of issue

commons-logging.jar

https://commons.apache.org/proper/commons-logging/download_logging.cgi

2nd Error

As per error you have posted, your path of Chrome binary is not correct or Chrome binary is not placed at the same location.

You need to download the Linux binary from below location :

https://chromedriver.storage.googleapis.com/index.html?path=2.32/

Note:- download binary as per your OS which seems Linux in your case.