Issue
I'm trying to run my test (Selenium+junit+cucumber+Maven) on Jenkins. In my definition class I'm not pointing to Chrome binary but rather use WebDriverManager:
@Given("^I navigate to page$")
public void i_navigate_to_webpage() throws Throwable {
String url = Helper.getPropValue("landing", "navigation");
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
wait = new WebDriverWait(driver,20);
driver.manage().window().maximize();
driver.get(url);
}
It works fine on my machine (Win), but when I'm trying to execute this on Jenkins (Ubuntu box), I get error:
org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary (Driver info: chromedriver=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881),platform=Linux 4.4.0-1047-aws x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 687 milliseconds Build info: version: '2.48.2', revision: '41bccdd10cf2c0560f637404c2d96164b67d9d67', time: '2015-10-09 13:08:06' System info: host: 'ip-172-31-12-150', ip: '172.31.12.150', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-1047-aws', java.version: '1.8.0_151' Driver info: org.openqa.selenium.chrome.ChromeDriver at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:247) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:129) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:142) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:170) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:159) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:116) at GridTest.grid.StepDef.i_navigate_to_webpage(StepDef.java:52) at ✽.Given I navigate to page(src/test/test.feature:6)
I was under impression that WebDriverManager should have covered that how it does on my Windows machine. Isn't it so?
My Pom.xml file here:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>GridTest</groupId>
<artifactId>grid</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>grid</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<suiteXmlFile>testing.xml</suiteXmlFile>
</properties>
<build>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
com.lazerycode.selenium
</groupId>
<artifactId>
driver-binary-downloader-maven-plugin
</artifactId>
<versionRange>
[1.0.17,)
</versionRange>
<goals>
<goal>selenium</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>cucumber-extentsreport</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.48.2</version>
</dependency>
</dependencies>
</project>
Solution
Your chrome on Ubuntu is not installed into default location:
you can add the chrome binary to PATH
environent variable or reinstall it to default location.
Make sure chromedriver compatible with chrome browser, check this link to get compatible mapping
Chromedriver 2.35 Supports Chrome v62-64
When run script from Linux terminal tunnel, like run by Jenkins.
In general, Linux terminal tunnel not have display screen, but run script with headful model require a physical or virtual display.
Option 1: run with headless
model when not setup virtual display by xWindow/xvbf
ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
// Must maximize Chrome by `start-maximized`
options.addArguments("start-maximized");
//Dont maximize Chrome by below line, because has no display
driver.manage().window().maximize()
Option 2: run with headful
model, but need setup virtual display for the user which Jenkins used to connect to your Ubuntu box or you setup for all users
if you can't know which user.
Please read document about Xvbf or other xWindow to setup virtual display.
Answered By - yong
Answer Checked By - Marie Seifert (JavaFixing Admin)