Set up the first Web Driver project in Eclipse

Setting up the first Web Driver project in Eclipse is very easy.

Please follow the next checklist for it:


1. download the Web Driver client and server ZIP files  and extract them in a folder



2. download the Chrome Web Driver ZIP file

3. extract the EXE file from the archive and copy it in the Chrome browser home folder





4. create a project in Eclipse


5. add the server and client JAR files to the project in Eclipse



6. create a basic test case

import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class TestClass {

public static WebDriverWait wait;
public static WebDriver driver;

@BeforeClass
public static void setUp() 
{
System.setProperty("webdriver.chrome.driver",       "C:\\Users\\asiminiuc\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe"); 

driver = new ChromeDriver();            
}

@AfterClass
public static void tearDown() 
{
driver.quit();
}

@Test
public void testMethod() throws InterruptedException
{

driver.get("http://www.google.ca");

WebElement element;

element = driver.findElement(By.xpath("//input[@id='gbqfq']"));
assertTrue(element.isDisplayed() == true);
}
}

7. run the project


Share this