My Thoughts: Starting Chrome Browser using WebDriver(Selenium2) with example

Thursday, May 10

Starting Chrome Browser using WebDriver(Selenium2) with example


If we would like to run our scripts on Chrome we need "chromedriver"along with the actual Chrome Browser.If you try to start the Chrome Browser with the below statement alone
WebDriver driver = new ChromeDriver();

Then you will notice below error statements

"You need to have both chromedriver and a version of chrome browser installed
@BeforeTest setUpDriver
java.lang.IllegalStateException: The path to the chromedriver 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://code.google.com/p/chromedriver/downloads/list
at com.google.common.base.Preconditions.checkState(Preconditions.java:172)
atorg.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:114)"

In our scripts if we dont specify where is chromedriver is located then we cant start chrome browser using WebDriver.

Here are steps to setup chromedriver

1.Download chromedriver from
http://code.google.com/p/chromedriver/downloads/list
2.Unzip the file .Say you downloaded it on your desktop folder named "Automation" and unzipped it then location will be like
C:\\Users\\<<User Name>>\\Desktop\\Automation\chromedriver_win_19.0.1068.0\\chromedriver.exe
3.Use the below code to start chrome
System.setProperty("webdriver.chrome.driver","C:\\Users\\<<UserName>>\\Desktop\\Automation\\chromedriver_win_19.0.1068.0\\chromedriver.exe"); 
ChromeDriver driver = new ChromeDriver();

Now you are done. :)

If you are using the TestNG framework then here is the sample code :

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class chromeDriver {
 
WebDriver  driver;

@BeforeTest
 public void setUpDriver(){
   System.setProperty("webdriver.chrome.driver",
"C:\\Users\\<>\\Desktop\\Automation\\chromedriver_win_19.0.1068.0\\chromedriver.exe");  
   driver = new ChromeDriver(); 
     }

 @Test
 public void start(){
 driver.get("http://www.google.com/"); 
   }

}


6 comments:

  1. This is the great job for providing the nice opportunity in this blog. I had really like this information and adding two things in this technology.

    ReplyDelete
  2. This was GREAT! THANKS!! Everth was clear and perfectly answered my problem! )) // Alex A.

    ReplyDelete
  3. Excellent, whะฐt a weblog it is! This weblog provides useful facts to us, keep it up.
    Also visit my web-site : tickets online

    ReplyDelete
  4. I do ัonsider ะฐll of the ัoncepts yฮฟu've introduced on your post. They are very convincing and can definitely work. Nonetheless, the posts are too short for novices. Could you please lengthen them a little from subsequent time? Thank you for the post.
    Feel free to surf my homepage Calling Cards

    ReplyDelete
  5. srinivasa reddy kothaFriday, April 26, 2013

    chrome web driver is working. but when click on the any menu links in web page, brothersoft tool bar is installed. brothersoft header is displayed in the chrome wed driver browser, same code is working in FF and IE.

    ReplyDelete
  6. WebDriver will always open the browser in incognito window.This is not something to do with WebDriver.


    I tried playing on google site and it worked fine.

    Can you try on other website ?

    ReplyDelete