Running Selenium Tests with ChromeDriver on Linux

Some of the pre-requisites has to be setup to execute the Selenium WebDriver tests with chromedriver on Linux

Download the following Softwares before starting to write tests in eclipse.

  1. Download Google Chrome – Chrome for Linux
  2. Download ChromeDriver – ChromeDriver for Linux

Install the Google Chrome on the Linux ennvironment by using the following methods:

  1. Double click or use rpm command if the package is “.rpm” (am currently using Fedora) to install the google chrome
  2. Use apt-get / YUM command to download and then install the package for different Linux flavors accordingly

Executing ChromeDriver Server:

  1. Inside /home/${user} – create a new directory “ChromeDriver”
  2. Unzip the downloaded chromedriver into this folder
  3. Using chmod +x filename or chmod 777 filename make the file executable
  4. Go to the folder using cd command
  5. Execute the chrome driver with ./chromedriver command
  6. Now the chromedriver will start executing in the 9515 port
[seetaram@Linux chromedriver]$ ./chromedriver
Started ChromeDriver
port=9515
version=14.0.836.0

Above is the output of the chromedriver server executing in Linux terminal.

After the above is accomplished, try to setup the test on the eclipse

  1. Download the Selenium server 2.0
  2. Download JUnit
  3. Unzip both the files and configure them to build path in the eclipse
  4. Write the test code as below in the Eclipse – Java file
package com.selftechy.wdriver;

import java.io.File;
import java.io.IOException;
import java.net.*;

import org.junit.*;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class ChromeRemoteDriver {
    
    public static void main(String []args) throws MalformedURLException{
        new DesiredCapabilities();
            URL serverurl = new URL("http://localhost:9515");
            DesiredCapabilities capabilities = DesiredCapabilities.chrome();
            WebDriver driver = new RemoteWebDriver(serverurl,capabilities);
        driver.get("http://www.google.com");
        WebElement searchEdit = driver.findElement(By.name("q"));
        searchEdit.sendKeys("Selftechy on google");
        searchEdit.submit();

    }
}

Now, try to execute the code by clicking Run As –> JUnit Test.  It should be executing the test to the completion.

Comments 10

  • Thank you very much. That was great tip. It pointed me to the right direction. My only ask is to add more detail on how to configure and setup the chromedriver on eclipse. I believe you have to set the system property but how.

  • Your last line creating confusion “try to execute the code by clicking Run As –> JUnit Test. It should be executing the test to the completion”. Change it as “Java Application” or change the code in junit.

    • You are misunderstanding… If you are trying to run JUnit test then you should use RunAs –> JUnit Test, If it is a Java program with main() method then you should use “Java Application”

  • Thanks for this. But i am getting an error that The driver is not executable, when i try to run the code on bamboo.

  • Hi,
    Chrome : version : 63.0.3239.84 (Official Build) (64-bit)
    Chromedriver : 2.34
    Selenium server : 3.7.1

    still unable to execute, getting the below error
    Could someone please help me in resolving the issue. struggling and searching for answer from many days.

    Starting ChromeDriver 2.34.522913 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5) on port 11458

    Only local connections are allowed.

    Exception in thread “main” org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally

    (Driver info: chromedriver=2.34.522913
    (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5),platform=Linux
    4.10.0-28-generic x86_64) (WARNING: The server did not provide any
    stacktrace information)

    Command duration or timeout: 60.10 seconds

    • Hi Divya,

      There is some issue with the Chrome. Try to update the chrome to latest version. Wherever you get this error, at that point in the code try to wait for some time. I mean use some sleep time. That should solve your problem.

    • Please Update your chrome browser to latest version these is due to dependency of previous versions

  • I am a little confused. We started the web driver in Linux. But the second part talking about eclipse is running on windows? Or you are talking about running on Linux desktop?

  • Hi,

    I am not able to run selenium scripts in linux machine.
    chrome version: 77
    Driver version: 77

    I am executing below code in windows and its working but same when I execute in linux machine its not working.
    I have changed chrome driver path(I have set the path where it is)

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;

    public class Test {
    public static void main(String[] args){

    WebDriver driver = null;
    try {
    System.setProperty(“webdriver.chrome.driver”, “C:\\Users\\vinodkumar.patil\\Documents\\Selenium jars\\chromedriver\\chromedriver.exe”);
    driver = new ChromeDriver();
    driver.manage().window().maximize();
    driver.get(“https://gryphon.datagenic.net/app/”);
    System.out.println(driver.getTitle());
    }
    catch(Exception e)
    {

    }

    }
    }

    POM.XML

    4.0.0

    DemoCucumberMavan
    DemoCucumberMavan
    0.0.1-SNAPSHOT
    jar

    DemoCucumberMavan
    http://maven.apache.org

    UTF-8

    info.cukes
    cucumber-java
    1.2.5
    test

    info.cukes
    cucumber-jvm-deps
    1.0.5
    test

    info.cukes
    cucumber-testng
    1.2.5
    compile

    junit
    junit

    org.testng
    testng
    6.9.8
    test

    net.masterthought
    cucumber-reporting
    3.8.0

    org.seleniumhq.selenium
    selenium-remote-driver
    3.0.0-beta2

    com.squareup.okio
    okio
    1.0.0

    org.seleniumhq.selenium
    selenium-java
    2.53.1

    org.seleniumhq.selenium
    selenium-support
    2.53.1

    com.google.code.gson
    gson
    2.8.6

    junit
    junit
    4.12
    test

    org.jetbrains.kotlin
    kotlin-stdlib
    1.3.50

    com.vimalselvam
    cucumber-extentsreport
    3.1.1

    com.aventstack
    extentreports
    4.0.0

    org.apache.maven.plugins
    maven-resources-plugin
    2.4

    org.apache.maven.plugins
    maven-surefire-plugin
    2.14.1

    testng.xml

    net.masterthought
    maven-cucumber-reporting
    3.8.0

    execution
    verify

    generate

    DemoCucumberMavan
    target/cucumber-reports/advanced-reports
    target/cucumber-reports/CucumberTestReport.json
    1
    false

    Please suggest me if I am missing any steps.

    Thanks in advance.

  • When running the above demo, I’m getting:

    “`
    May 13, 2022 11:51:26 PM org.openqa.selenium.remote.DesiredCapabilities chrome
    Exception in thread “main” org.openqa.selenium.WebDriverException: chrome not reachable
    Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:53’
    “`

    Why is that and how to fix? Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.