Selenium Webdriver Introduction

Selenium is a framework used for testing of web applications. It is open-source software, used for Automation Testing, which supports different browsers and platforms. You can even write your test cases in number of programming languages. It is composed of four components –

  • Selenium Remote Control(RC) or Selenium 1 — 2004
  • Selenium Integrated Development Environment(IDE) — 2006
  • Webdriver — 2007
  • Selenium Grid (Initially Hosted QA) — 2008

To successfully cope up with the advanced and more secured web-applications & web-browsers and to overcome some limitations in Selenium RC, Simon Stewart created Webdriver. Later in 2009, to enhance performance, Selenium RC was merged with Webdriver, and known as Selenium 2.0 or Selenium WebDriver. With this Selenium RC has been deprecated officially. Selenium Webdriver is fully supported by Java, Python, Ruby and C#.

With the invention of Selenium Webdriver, Selenium Server is not mandatory nowadays. However it will be required in case you want to use Selenium Grid (to distribute load of your test cases on several machines).Otherwise browser will be run by Webdriver directly. The specific driver of the browser is responsible for all the communications with the web-application. It will send commands to the browser and also retrieves results. Webdriver will launch the browser, using the built-in support provided for automation by browser.

One can also use HtmlUnitDriver with the use of Selenium Server.

Creating an instance of Internet Explorer Driver-

WebDriver driver = new InternetExplorerDriver();

But before creating driver instance, you have to set System property (say path of your ieDriver is “C:/drivers/IEDriverServer.exe”) 

System.setProperty(“webdriver.ie.driver”,”C:/drivers/IEDriverServer.exe”);

You can also set log properties

System.setProperty(“webdriver.ie.driver.loglevel”,”DEBUG”); 
System.setProperty(“webdriver.ie.driver.logfile”,”C:/drivers/IEDriverServer.log”);

 

Simple example –
To search “Pizza” on google search –

public class GoogleSearchPizza {

public static void main(String args[]){

System.setProperty(“webdriver.ie.driver”,”C:/drivers/IEDriverServer.exe”);

System.setProperty(“webdriver.ie.driver.loglevel”,”DEBUG”);

System.setProperty(“webdriver.ie.driver.logfile”,”C:/drivers/IEDriverServer.log”);

WebDriver webDriver = new InternetExplorerDriver();

webDriver.get(“http://google.com”);

WebElement searchBox = webDriver.findElement(By.id(“lst-ib”));

searchBox.clear();

searchBox.sendKeys(“Pizza”);

WebElement searchButton = webDriver.findElement(By.id(“_Fzl”));

searchButton.click();

webDriver.quit();

           }

}