Running Selenium test case in Google Chrome? – User friendly Tech help

We have already learned to execute selenium test case in Firefox browser . Now we thought of running the same test on “Google Chrome”.
n
nRequirement:- Executing selenium webdriver test case in Google chrome for the first time.
n
nSolution:-
nWe simply tried to change the previous code and passed the reference of “chromedriver”.
n
nBefore :-
n  WebDriver driver = new FirefoxDriver();
nAfter:-
n  WebDriver driver = new ChromeDriver();
n
nBut !!! On our execution of the test case we encountered a below error message:-
n

n

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)

n

n
nThis error message was a hint for our solution. We followed this to solve the puzzle of running our test on chrome.
n
nStep1:- We need to download the “ChromeDriver“(Given in the above error message)
nLink :– http://chromedriver.storage.googleapis.com/index.html

n

n

n

n

n

n

n

n

Download the latest version 

n

n

n

n

n

n

n

n

Check the OS

n

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

n

nStep2:– Extract the file (chromedriver.exe)

n

nStep3:-We need to use the “System Property” to create a bridge between the selenium webdriver and google chrome.
n
nSyntax:-System.setproperty(key,value);
n Key = “webdriver.chrome.driver”
n Value = “chromedriver.exe”, Absolute path of chromedriver , (Refer Step-2 above)
n
nCode:-
n

nimport org.openqa.selenium.WebDriver;
nimport java.lang.*;
nimport org.openqa.selenium.chrome.ChromeDriver;
nimport org.openqa.selenium.firefox.FirefoxDriver;
npublic class LearnSelenium {n

public static void main(String[] args) {

n
n//Creating WebDriver Object
nSystem.out.println(“Launching the Browser”);
n//WebDriver driver = new FirefoxDriver();
nSystem.setProperty(“webdriver.chrome.driver”, “D:\Automation\Selenium\MyCode\chromedriver_win32\chromedriver.exe”);
nWebDriver driver = new ChromeDriver();
n//Opens the given URL
ndriver.get(“http://www.uftHelp.com”);
nSystem.out.println(“Fetching the Title”);
nSystem.out.println(“Please Wait!!”);
n//Returns the Title of Current Page
nString sTitle = driver.getTitle();
nSystem.out.println(“My First Selenium Program”);
nSystem.out.println(“Title is = ‘”+sTitle+”‘” );
n//Closing the Browser
ndriver.close();
n}n

}

n
n

Some crucial tips for selenium automation testing

Was this article helpful?
YesNo

Similar Posts