Tuesday 22 January 2013

SELENIUM WEBDRIVER

What is Selenium Webdriver?
Webdriver is known to be the latest version of Selenium i.e. Selenium 2.x. More powerful than the primitive Selenium rc 1.x and comes with lots and lots of libraries and new features to work with. It's not mandatory to know Selenium RC to work with Webdriver. You can directly learn webdriver and start working on it. There is no need of selenium server if you are working with Webdriver API

What makes it different from Selenium RC?
    More object oriented as compare to Selenium RC.
    Has wider range of APIs
    Interacts natively with browser where as Selenium RC is Javascript based.
    Can test Iphone and Andriod based application which is not supported by Selenium RC.
    Implements HTMLUnit driver which makes test execution really fast.
    Unlike Selenium RC there is no server in Webdriver.
    Supports almost all lastest web browsers where as Selenium RC does not works on latest versions on Firefox and IE.

How to configure Selenium Webdriver?

Pre Requisite:
    Install Firefox
    Install Java
    Download Selenium 2.0 libraries

Getting Started:
Open Elipse and create a new Java project. Create a new class and import the downloaded Selenium Webdriver libraries

Writing the first Selenium Webdriver code:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Webdriver_module_1 {
public static void main(String[] args) {
   WebDriver driver = new FirefoxDriver();
   driver.get("http://google.com");
   System.out.println(driver.getTitle());
   driver.close();
   driver.quit();
  }
}

Create a new class file and copy paste the above code. Now run it as a Java application.

Basic Webdriver methods:
    driver.get() - Takes you to the provied URL/Website address.
    driver.getTitle() - Get the title of the current browser window.
    driver.getPageSource() - Get the page source code of the current window.
    driver.close() - Closes the current window.
    driver.quit() - Close all associated windows.
    driver.getCurrentUrl() - Get the URL of the current webpage.

No comments:

Post a Comment