SELENIUM WEBDRIVER- A TEST STRATEGY

Selenium is a automation tool for Testing, which are collection of different tools for Automation Testing. Selenium is not just a single tool but a suite of software, each catering to different testing needs of an organization. It has four components.

  • Selenium Integrated Development Environment (IDE)
  • Selenium Remote Control (RC)
  • Webdriver
  • Selenium Grid

Why Webdriver:

WebDriver is a tool for automating testing web applications, and in particular to verify that they work as expected. It aims to provide a friendly API that’s easy to explore and understand, which will help make your tests easier to read and maintain. It’s not tied to any particular test framework, so it can be used equally well with JUnit, TestNG or from a plain old “main” method.

This “Getting Started” guide introduces you to WebDriver’s Java API and helps get you started becoming familiar with it. Webdriver allows your test scripts to communicate directly to the browser, thereby controlling it from the OS level.

  • To open source
  • To use a certain programming language in designing your test case
  • To test applications that are rich in AJAX-based functionalities
  • To execute tests on the HtmlUnit browser
  • Create scripts in Multi language (Java, perl, c# and phyton)
  • Run the Script on different type of browser.

Web Driver uses a different underlying framework from Selenium’s java-script Selenium-Core. It also provides an alternative API with functionality not supported in Selenium-RC. WebDriver does not depend on a JavaScript core embedded within the browser; therefore it is able to avoid some long-running Selenium limitations.The Selenium developers strive to continuously improve Selenium.

Integrating WebDriver is another step in that process. The developers of Selenium and of WebDriver felt they could make significant gains for the Open Source test automation community be combining forces and merging their ideas and technologies. Integrating WebDriver into Selenium is the current result of those efforts.

Advantages of Selenium Webdriver:

  • Improved features & functionality which were not supported in the Selenium 1.0
  • No need to start server prior to start executing scripts
  • Added advantage to support for iPhone and Android testing
  • It supports features like Page navigation, Drag-and-drop and AJAX-based UI elements
  • Using WebDriver can easily find the coordinates of any object
  • WebDriver is open source & it allows you to easily integrate with testing framework like JUnit or TestNG
  • It provides the improved reliability between browsers
  • For web application testing, it provides standard programming interface

Working Principles:

Picture1

Selenium 2.0 (Webdriver), the supported browsers vary depending on whether you are using Selenium-Webdriver scripts like Firefox, IE, Safari or Chrome.We can write the testing scripts and run in any browser and finding the result easily. If we writing a script for Fire fox browser, we can change the same script for IE or other browser with a little change like browser name. So we can create a single script and run it on different browser.

Scripts:

Here we can create a script and run it in different browser. In he bellow example scripts developed for Firefox.

package example;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class drive {
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.get(“http://www.betterlives.world/”);
String actualTitle = driver.getTilte();
String expectedTitle = “PROBESEVEN :: Online Branding Company”;
String actualTitle = “”;
if (actualTitle.contentEquals(expectedTitle))
{
System.out.println(“Test Passed!”);
}
else
{
System.out.println(“Test Failed”);
}
//close Firefox
driver.close();
// exit the program explicitly
System.exit(0);
}

Run in Different browser:

The last example script only run in Firefox browser. If we want to run the same script in Chrome or IE browser, just we make some little changes are enough in the script. For example, instead of Firefox driver, we can replace it by Chrome driver.

WebDriver driver = new ChromeDriver();

In case, we change it to Chrome Driver means, the same script run on Chrome driver and we can find the result too.

TestNG and JUnit:

TestNG and JUnit are the mostly used frameworks in selenium webdriver for reporting the bugs in document format like excel sheet. JUnit is a unit testing framework for the Java programming language. JUnit has been important in the development of test-driven development. To execute Selenium WebDriver testing using JUnit we have to add JUnit annotations in your test. Using these two methods we can have the inputs from excel sheet and process the inputs and generate the output by selenium result to excel sheet.

Selenium IDE:

IDE is a excellent play and back tool with Firefox add-on. We can start the IDE add-on and continue our web application testing. Here each and every clicking and opened pages are stored by IDE and finally it produce the results.

The Selenium IDE is an excellent starting point to start using and learning Selenium. For a short description, the Selenium IDE is a plugin for the Firefox browser that let’s one click and record actions in the web browser. In addition, it adds options to your contextual menu (the right click menu) that helps you create tests.

As a result, you can very quickly create and prototype scripts for automation. The IDE should come up so we’re well on our way to creating our first automated script using the IDE. For our first script, let’s pretend we’re working at Google and we want to make sure that when someone searches for something, their query remains in the search field on the results page.  Before we get to creating our script, let’s familiarize ourselves with some of the basic functionality as well as the UI.