Selenium WebDriver Tutorial 1

Introduction to Selenium WebDriver

i) Introducing Selenium WebDriver

ii) Selenium WebDriver Environment Setup

iii) Write first Selenium Test Case
----------------------------------------
i) Introducing Selenium WebDriver

Selenium Tool's Suite
    Selenium IDE
    Selenium RC
    Selenium WebDriver
    Selenium Grid
--------------------------------------
Selenium WebDriver

> In 2006 Selenium WebDriver was launched at Google.

> In 2008, the whole Selenium team decided to merge Selenium Webdriver with Selenium RC in order to form more powerful tool called Selenium 2.0.

Selenium 1.0 + Selenium WebDriver  = Selenium 2.0

Selenium 1.0

(Selenium IDE + Selenium RC + Selenium Grid)

Selenium 2.0

(Selenium IDE + Selenium RC + Selenium WebDriver + Selenium Grid)

Note: Now Selenium RC is only for maintenance projects.
----------------------------------------
Selenium WebDriver Features

> It is a most important tool in Selenium suite.

> It has Programming interface only, no IDE.
--------------------------
Selenium IDE - we can create Test cases using Recording features and enhance Test cases using Selenese commands. (No Programming)

Selenium WebDriver - we can create Test cases using Element locators and Webdriver methods/commands. And we can use programming features to enhance Test cases.

UFT/QTP - we can create Tests using Tool features (Recording) and enhance Test cases using Tool features (Checkpoints, Output values etc...) as well as Script/Program features (Conditional statements, Loop statements functions etc...).
-------------------------------------------------------
> Selenium WebDriver supports various programming languages to write programs (Test Scripts)

Java
C#
Python
Perl
Ruby
PHP

> Selenium WebDriver supports various Browsers to create and execute Test cases.

Mozilla Firefox

Google Chrome

IE

Safari

Opera etc...
------------------------------------
> Selenium WebDriver supports various operating environments.

MS Windows

Linux

Macintosh etc...
-------------------------------------------
> Selenium WebDriver supports Data Driven Testing and Cross Browser Testing

> Selenium WebDriver is faster in execution than other tools of Selenium suite.

> Selenium WebDriver supports parallel test execution with the help of either JUnit or TestNG framework.

> Selenium WebDriver supports Batch Testing with the help of either JUnit or TestNG framework.
----------------------------------------
Drawbacks of Selenium WebDriver:

> Selenium WebDriver doesn't have IDE (takes more time and more efforts to create Test cases)

> No built in Result Reporting facility.

> No other tool integration for Test Management.
---------------------------------------------------
How we create Test Cases / Test Scripts / Tests in Selenium WebDriver

Selenium IDE:

Using Element locators and Selenese (Selenium IDE) Commands.

Selenium WebDriver

Using element Locators and WebDriver Methods /Commands.

UFT/QTP

Using Objects Information and Test Methods.
-------------------------------------------
Element Locators - to recognize elements /objects.

WebDriver Methods/Commands - to perform operations on elements.
----------------------------------------------------------
Java Programming - to enhance Test cases.

JUnit / TestNG Framework - to group Test cases, batch testing and generating Test Reports.
----------------------------------------------
ii) Selenium WebDriver Environment Setup

Steps:

i) Download and install Java (JDK) software. - To create and execute programs (Test scripts)

ii) Set Environment variable path (Path Variable) - To use Java from any directory.

iii) Download Eclipse IDE and extract. - To write and execute Java programs.
----------------------------------
iv) Download Selenium WebDriver Java Language binding (from www.seleniumhq.org) and add WebDriver jar files to Java project in Eclipse IDE.
------------------------------------------------ 
v) Install Firebug and Firepath plug ins for Mozilla Firefox Browser to inspect elements.

Or Use built in tools to inspect elements

Mozilla Firefox - Page Inspector

Chrome, IE - Developer tools
--------------------------------------------
vi) Firefox Driver is default driver in Selenium Webdriver, for IE, Chrome and Safari etc... Browsers we need to download browser drivers and set path.
-------------------------------------------------------------------------
Download Selenium WebDriver Java language binding and extract.

Add Selenium WebDriver jar files to Java project in Eclipse IDE.

Navigation:

Create Java Project
> Select Java project and right click
> Build path
> Configure Build path
> Select Libraries tab
> Click "external jars"
> Browse path of Selenium Webdriver jars.
> Add
--------------------------------------
Create Selenium WebDriver Test Case

> Import WebDriver and Firefox/IE/Chrome libraries. (In The Test Case/Program)

> Using Element locators and WebDriver Commands/methods write Test steps.

> Insert Java programming statements to enhance Test cases.
----------------------------------------
iii) Write first Selenium Test Case

Manual Test Case:

Test Case ID: gcrshop_admin_TC001

Test Case Name: Verify Admin Login in GCR Shop web portal

Test Steps:
i) Launch the Browser and navigate to "www.gcrit.com/build3/admin"
ii) Enter User name
iii) Enter Password
iv) Click "Login" Button

Input Data / Test Data:
User name =admin
Password = admin@123

Expected URL: "www.gcrit.com/build3/admin/index.php"

Actual URL: http://www.gcrit.com/build3/admin/index.php

Test Result: Pass
----------------------------------------
Selenium WebDriver Test Case:

public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();//Launches Firefox Browser with blank url.
driver.get("http://www.gcrit.com/build3/admin/login.php");//Naviage to Admin home page
driver.findElement(By.name("username")).sendKeys("admin");
driver.findElement(By.name("password")).sendKeys("admin@123");
driver.findElement(By.id("tdb1")).click();

String url = driver.getCurrentUrl();

if (url.equals("http://www.gcrit.com/build3/admin/index.php")){
System.out.println("Login Successful - Passed");   
}
else {
System.out.println("Login Unsuccessful - Failed");
}
driver.close();//Closes the Browser
}
}
------------------------------------------------------------

No comments:

Post a Comment