Running
Selenium Webdriver Test In Google Chrome
You
can read my POST-38 to know how to run selenium
webdriver test of software application in Mozilla Firefox browser. As
you know, webdriver software testing tool support Google Chrome browser too.
You need to do something extra for launching webdriver test in in
Google chrome browser. Let me describe you steps to launch webdriver
test in Google Chrome for software web application.
Download ChromeDriver
server
First of all, download latest
version of ChromeDriver server for webdriver software testing tool. You can
download it directly from https://sites.google.com/a/chromium.org/chromedriver/downloads. Current
latest version for win32 is "ChromeDriver 2.15" as shown below.
Click on "ChromeDriver 2.15" link. It
will take you to download page
Click on link shown above to download chrome driver zip file.
On completion of download, extract zip file to D:/ drive
Now in eclipse, create new project with name =
'chromeproject' and create new class with name = 'chromebrowser'. Don't forget
to select 'public static void main(String[] args)' method during new java class
creation. Write code as shown below in class file.
package mytestpack;
import
java.util.concurrent.TimeUnit;
import
org.openqa.selenium.By;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.chrome.ChromeDriver;
public class chromebrowser
{
public
static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver",
"D:\\chromedriver_win32\\chromedriver.exe");
WebDriver
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10,
TimeUnit.SECONDS);
driver.get("http://www.google.com");
if
(driver.findElement(By.xpath("//input[@name='q']")).isEnabled())
{
System.out.println("Google search text box Is enabled.");
driver.findElement(By.xpath("//input[@name='q']")).sendKeys("WebDriver
Test successful.");
driver.findElement(By.xpath("//button[@name='btnG']")).click();
System.out.println("Google
search completed.");
}
else
{
System.out.println("Google
search test box Is Not enabled.");
}
driver.close();
}
}
Look in to above
example. I set path for Google chrome driver as
System.setProperty("webdriver.chrome.driver",
"D:\\chromedriver_win32\\chromedriver.exe");
So
now, your software web application's test will run in Google chrome browser.
Nice post..
ReplyDeleteIs there any specific version to download for selenium java client driver 2.45.0?