Running Selenium test case in Google Chrome?

We have already learned to execute selenium test case in Firefox browser . Now we thought of running the same test on “Google Chrome”.

Requirement:- Executing selenium webdriver test case in Google chrome for the first time.

Solution:-
We simply tried to change the previous code and passed the reference of “chromedriver”.

Before :-
  WebDriver driver = new FirefoxDriver();
After:-
  WebDriver driver = new ChromeDriver();

But !!!

On our execution of the test case we encountered a below error message:-

Exception in thread “main” java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html at com.google.common.base.Preconditions.checkState(Preconditions.java:177) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105) at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:89) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:117) at LearnSelenium.main(LearnSelenium.java:10)



This error message was a hint for our solution. We followed this to solve the puzzle of running our test on chrome.

Step1:- We need to download the “ChromeDriver“(Given in the above error message)
Link :– http://chromedriver.storage.googleapis.com/index.html

Chromedriver download
Download the latest version 


ChromeDriver for selenium
Check the OS

 Note:-
 We can check the latest bug fixes from notes.txt
 For other Drivers download 


Step2:– Extract the file (chromedriver.exe)


Step3:-We need to use the “System Property” to create a bridge between the selenium webdriver and google chrome.

Syntax:-System.setproperty(key,value);
 Key = “webdriver.chrome.driver”
 Value = “chromedriver.exe”, Absolute path of chromedriver , (Refer Step-2 above)

Code:-

import org.openqa.selenium.WebDriver;
import java.lang.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class LearnSelenium {

public static void main(String[] args) {
//Creating WebDriver Object
System.out.println("Launching the Browser");
//WebDriver driver = new FirefoxDriver();
System.setProperty("webdriver.chrome.driver", "D:\Automation\Selenium\MyCode\chromedriver_win32\chromedriver.exe");
WebDriver driver = new ChromeDriver();
//Opens the given URL
driver.get("http://www.uftHelp.com");
System.out.println("Fetching the Title");
System.out.println("Please Wait!!");
//Returns the Title of Current Page
String sTitle = driver.getTitle();
System.out.println("My First Selenium Program");
System.out.println("Title is = '"+sTitle+"'" );
//Closing the Browser
driver.close();
}

}

Some crucial tips for selenium automation testing

ufthelp

4 thoughts on “Running Selenium test case in Google Chrome?

Leave a Reply

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