Selenium + Java + Chrome Driver ( WebDriver ) : quick setup

Trabla: Selenium + Java + Chrome Driver ( WebDriver ) : quick setup


Solving: 

OS: Windows

ChromeDriver is a separate executable that WebDriver uses to control Chrome.
This tutorial shows how to quickly set up selenium environment to use ChromeDriver.

1. Install Java Development Kit ( JDK )

2. Install Eclipse

3. Run Eclipse and create new Java Project, name it "ChromeDriverQuickStart"



Howto setup Selenium + Java + Chrome Driver ( WebDriver ) : quick setup - codingtrabla tutorial 1

Howto setup Selenium + Java + Chrome Driver ( WebDriver ) : quick setup - codingtrabla tutorial 2

Howto setup Selenium + Java + Chrome Driver ( WebDriver ) : quick setup - codingtrabla tutorial 3


4. Download selenium  standalone .jar file
- page - http://www.seleniumhq.org/download/

Howto setup Selenium + Java + Chrome Driver ( WebDriver ) : quick setup - codingtrabla tutorial 4


5. Drag and drop  selenium-server-standalone-2.47.1.jar  into eclipse project "src" folder

Howto setup Selenium + Java + Chrome Driver ( WebDriver ) : quick setup - codingtrabla tutorial 5



6. Add selenium-server-standalone-2.47.1.jar into build path

Howto setup Selenium + Java + Chrome Driver ( WebDriver ) : quick setup - codingtrabla tutorial 6
Howto setup Selenium + Java + Chrome Driver ( WebDriver ) : quick setup - codingtrabla tutorial 7

Howto setup Selenium + Java + Chrome Driver ( WebDriver ) : quick setup - codingtrabla tutorial 8


7.  Download chromedriver from
http://chromedriver.storage.googleapis.com/index.html?path=2.18/
and unzip file.
Copy full path to file  chromedriver.exe  after unzipping ( will need in step 8 )
e.g. on my PC :

C:\Users\SamuraiKit\Downloads\chromedriver_win32\chromedriver.exe

Howto setup Selenium + Java + Chrome Driver ( WebDriver ) : quick setup - codingtrabla tutorial 9


8. Create new class "ChromeDriverTest" and copy following code

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;


public class ChromeDriverTest {

    public static WebDriver getChromeWebDriver(){
 

   
         // Path to chromedriver.exe:
         // C:\Users\SamuraiKit\Downloads\chromedriver_win32\chromedriver.exe             
         // Replace to yours
        System.setProperty(
                "webdriver.chrome.driver",
                "/Users/SamuraiKit/Downloads/chromedriver_win32/chromedriver.exe"
        );
       
        ChromeOptions options = new ChromeOptions();
        options.addArguments("window-size=1024,768");
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
       
        WebDriver driver = new ChromeDriver(capabilities);
       
        return driver;
    }
   
   
    public static void main(String[] args) { 
   
       
        WebDriver chrome = ChromeDriverTest.getChromeWebDriver();
       
       
        String url = "https://google.com";
       
        chrome.get(url);
       
        System.out.println("Page title is: " + chrome.getTitle());
       
    }
   
   
}



9. Run

No comments:

Post a Comment