Selenium Chrome WebDriver Test Cases with JUnit in Java

In this example we will show you how to run Selenium Chrome WebDriver Test Cases with JUnit in Java. In order to run Selenium Chrome Test Cases you need the ChromeDriver which you can download here. You need to set the location as a system property namely: You can add this property as a system property or you can pass the value as an argument to maven which I explained below.

Maven Dependencies

You need to add the following dependencies to your project.


Selenium Chrome WebDriver with JUnit

You need to create a ChromeDriver implementation of the WebDriver. You can do this by creating a new ChromeDriver(). This ChromeDriver needs to know where the executable file is located. You can tell this by setting the either by a System Property or you can pass this as a Maven Argument. After you initialized the ChromeDriver you can do the actual testing. For simplicity we just acquire a web resource. After the test is completed we need to clean up the WebDriver.

package com.memorynotfound.test;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.WebDriver;

public class ChromeSeleniumTest {

    private static WebDriver driver;

    public static void setUp(){
        System.setProperty("", "/selenium-driver/chromedriver");
        driver = new ChromeDriver();

    public void testChromeSelenium() {

    public static void cleanUp(){
        if (driver != null) {


Executing Selenium Chrome WebDriver Test Cases with Maven

When you execute the Selenium Chrome WebDriver Test Cases you can see that chrome start up a new instance and that the page is reached.

mvn clean test

Info: If you don’t want to hard code the location of the chrome driver, you can also pass the location of chrome driver as an argument to Maven.

mvn clean test


[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building SELENIUM - chrome-example 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------ 
 T E S T S
Running com.memorynotfound.test.ChromeSeleniumTest
Starting Selenium Chrome WebDriver 2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf) on port 36247
Only local connections are allowed.
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.492 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS (Selenium Chrome WebDriver)
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.483 s
[INFO] Finished at: 2015-02-06T19:22:13+01:00
[INFO] Final Memory: 15M/245M
[INFO] ------------------------------------------------------------------------



You may also like...