Running Selenium Tests with ChromeDriver on Linux

by seetaram on August 17, 2011

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.

{ 4 comments… read them below or add one }

afam April 25, 2013 at 12:03 am

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.

Reply

Manoj October 7, 2013 at 7:18 am

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.

Reply

seetaram October 8, 2013 at 9:21 am

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”

Reply

Sachin September 26, 2014 at 7:36 am

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

Reply

Leave a Comment

Previous post:

Next post:

Do you want to get updates on the recent articles written? Please subscribe to RSS feed or Email