Selenium for Beginners

Selenium Quick Reference

I) Selenium Fundamentals

i) What is Selenium?

> Selenium is a Suite of Tools to automate Browsers, Selenium can automate Web Applications only, It doesn't automate Desktop Applications.

> Selenium is open source software, anybody can download and use with free of cost.

ii) History of the Selenium Project

> Selenium first came to life in 2004 when Jason Huggins was testing an internal application at ThoughtWorks. He developed a Javascript library that could drive interactions with the page, allowing him to automatically rerun tests against multiple browsers.

> In 2006 an engineer at Google named Simon Stewart started work on a project he called WebDriver.

> In 2008, the whole Selenium Team decided to merge WebDriver and Selenium RC to form a more powerful tool called Selenium 2.

> Selenium RC is still being developed but only for maintenance.

iii) Selenium License

All Selenium projects are licensed under the Apache 2.0 License, It is Open source anybody can download and use selenium suite(Selenium IDE, Selenium RC, Selenium WebDriver and Selenium Grid) of tools with free of cost.

Note: Anybody can download and use Selenium components, but selling updated code is not permited.

iv) Selenium Supporting Platforms and Environments

a) Operating Systems:

Microsoft Windows   
UNIX/ Linux
Apple OS X etc...

b) Browsers:  

Mozilla Firefox
Internet Explorer
Google Chrome
Opera etc...

c) Scripting/Programming:


d) Software Applications

> CUI based Applications (* It doesn't support)

> Desktop Applications (I-Tier and II-tier Applications) (* It doesn't support)

> Web Applications (It Supports)

> Mobile Applications (*Which have web forms) (It supports)

v) Selenium suite of tools or Selenium Components

a) Selenium IDE:Selenium IDE, It is a tool for creating test cases.
It is a Firefox plugin and provides an easy-to-use interface for developing automated tests.

b) Selenium RCSelenium RC solves the limitations of Selenium IDE. It supports various programming languages like Java, C#, PHP, Perl, Python and Ruby languages to achieve logic required in test cases like conditional statements, iterations, exception handling, test reporting, database testing, capturing screen shots of failed tests, test case grouping etc...

c) Selenium WebDriverThe biggest change in Selenium recently has been the inclusion of the WebDriver API. Selenium WebDriver fits in the same role as RC did.

WebDriver is designed in a simpler and more concise programming interface along with addressing some limitations in the Selenium-RC API.

d) Selenium GridSelenium Grid allows you to run your tests in parallel, that is, different tests can be run at the same time on different remote machines.

vi) Advantages of Selenium

> It is Open source Software, no license cost, anybody can download and use with free of cost.

Selenium was first written in Java but it also supports C#, Ruby, Perl, PHP and Python. This is a big plus when we want to build our framework in a language that has the highest adoption in the organization it is being built within. Tools like UFT / QTP force you to use VBScript – which is almost never the preferred scripting language for developers.

>    It has support for all of the popular browsers like IE, Firefox, Chrome, Safari etc. It also supports several Operating Systems and that makes it a tool of choice for cross browser/ cross platform certification.

>    Once you get Selenium to work for you, it works reliably when used for running the tests over and over again. It’s definitely a lot more reliable than tools like QEngine or JExplorer but about the same as tools like UFT / QTP.

>    You can instantiate several concurrent tests (Parallel Test execution) with Selenium Grid.  

vii) Disadvantages of Selenium

> Supports Web based (Browser based) Application only, doesn't support Desktop or standalone Application test automation.

> Since it is Open source software, no reliable technical support from anybody.

> No centralized maintenance of Elements (Objects)

> Limited support for Image testing.

> Some new features may or may not work properly.

> Deploying Selenium Tool is difficult than UFT (Formerly QTP) Tool.

II) Java for Selenium

A) java Basics

i) Comments in Java 

Purpose of comments

    > To make the code readable
    > To make the Disable from execution

Java supports Single line comment and multiple lines comment.

ii) Data Types in Java
There are two categories of Data types in Java

a) Primitive data types

b) Reference data types

iii) Variables
a) Local variables

b) Instance variables

c) Class / Static variables

iv) Java Modifiers
Modifiers are used to set access levels for Classes, variables, methods etc...

a) Access Modifiers (Default, Public, Private, Protected)

b) Non-access Modifiers (Static, Final, Abstract, Synchronized)

v) Operators in java
Operators are used to perform mathematical, comparison and logical operations.

Categories of operators:

a) Arithmetic

b) Relational operators

c) Bit-wise operators

d) Logical operators

e) Assignment operators

f) Mise Operators

vi) Conditional statements

Used to insert verification points and for error handling.

Types of conditional statements in Java:

a) If Statement

b) Switch statement

Types of Condition:

a) Single condition

b) Compound conditions

c) Nested conditions

Usage of conditional statements:

a) Executing a block of statements when condition is true.

b) Execute a block of statements when condition is true otherwise execute another block of statements.

c) Decide among several alternates (Else if)

d) Executing a block of statements when more than one condition is true.(Nested if)

e) Decide among several alternates (Switch statement)

vii) Loop statements

used for repetitive execution.

Types of Loop Statements

a) For Loop

b) While Loop

c) Do...While Loop

d) Enhanced For Loop (mainly used for Arrays)

viii) Arrays in Java

Generally, Array is a collection of similar type of elements.

In Java, Array is an object that contains elements of similar data types.

Java Array is index based, index starts from zero.

The length of an Array is established when the Array is created and Array length is fixed.

Each item in an Array is called an Element.

Declaration of Arrays

Assigning values to elements

Advantages and Disadvantages of Arrays.
ix) Java Methods
Methods are also known as procedures or functions

A Java method is a collection of statements that are grouped together to perform an operation.



If you call the method, the system actually executes several statements, in order to display a message on the console.

We can create methods with or without returning any value.

Basically Methods are two types

a) Built-in or Pre-defined    

    Number Methods
    Character methods
    String methods
    Date & Time Methods

b) User defined    

    Method with returning value
    Method without returning any value
x) Regular Expressions
It is a formula for matching patterns, A Regular expression defines search pattern for strings.

Java provides the java.util.regex package for pattern matching with regular expressions.
xi) File and I/O operations in Java.
The package contains classes to perform input and output (I/O) operations in Java.

Reading using input devices

Displaying on the console

Reading and writing text files

Working with Excel files.
xii) Exception handling in Java
In Computer programming, Exception is an abnormal condition.

An exception is an event that occurs during the execution of a program that disrupts the normal flow of instructions.

The exception handling in java is one of the powerful mechanism to handle the runtime errors so that normal flow of the application can be maintained.
Java object oriented Programming
Class, Object, Method

In object oriented programming system(OOPS), we design a program using Objects and classes.


It is an entity that has states and behaviors is known as Object.

Ex: Pen, Chair, Table, Computer etc...

States / Properties of Dog object are color, height, weight etc... and behaviors moving, barking, jumping etc...

Class is a template or blueprint from with objects are created.

A Class a group of objects that has common properties.
Method: An operation on Object.
i) Inheritance
Inheritance is a mechanism in which one object acquires all the properties and behaviors of parent object.

Using Inheritance we can create classes that are built upon existing classes.

When we Inherit from an existing class, we can reuse methods and fields from parent class and we can add new methods and fields also.

Java Supports:

a) Single Inheritance

b) Multi level Inheritance

c) Hierarchical Inheritance

Note: Java doesn't support Multiple Inheritance.
ii) Polymorphism
If a class having multiple methods with same name, but different parameters is known as method overloading.

Method overloading increases the readability of the program.

There are two ways to overload the method in Java

a) by changing number of arguments
add (int a, int b)

add (int a, int b, int c)

b) by changing data types

add (int a, int b)
add (char a, char b)

In Object Oriented programming overriding means to override the functionality of an existing method.

Method overriding provides a specific implementation of a method that is already provided by its super class (Parent class)

It is used for runtime polymorphism.
It is a concept by which we can perform a single in different ways.

Polymorphism derived from two Greek word poly and morphs

Poly means -many
morphs means -forms / ways, so polymorphism means many forms.

we have two types of Polymorphism in java

a) Compile time polymorphism
b) Runtime polymorphism.

We can perform polymorphism in java by method overloading and method overriding.
iii) Abstraction
Abstraction is a process of hiding the implementation details and showing functionality to the user.

Another way, it shows important things to the user and hides internal details.

Ex: Sending email

you just type the email and send, you don't internal process of the email delivery.

Abstraction focuses on what the object does instead of how it does.

In two ways we can achieve Abstraction

a) Abstract Class (0 to 100%)

b) Interface (100%)
iv) Encapsulation
Encapsulation is one of the four fundamental oops concepts, other three are Inheritance, Polymorphism and Abstraction.

Encapsulation is a process of wrapping code and data together into a single unit.

Ex: Capsule (mixed of several medicines)

It provides the control over the data, suppose we want to value of the id greater than 100 only, we can write the logic inside the setter method.
Java packagesA Java package is a group of similar type of classes, interfaces and sub-packages.

There are two types of java packages

a) Built in packages

Ex: io, util, sql etc...

b) User defined packages

Interfaces in JavaAn interface is a collection of abstract methods.

An interface is not a class, writing an interface is similar to writing a class, but two are different concepts.

III) Selenium WebDriver

Selenium WebDriver Introduction:

> Selenium 1.0 (Selenium IDE + selenium RC + Selenium Grid)

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

Note: Selenium WebDriver merged with Selenium 1.0

> It is a most important tool in Selenium suite.

> It is has programming interface allows us to create and execute Test cases against different browsers (ex: Firefox, IE, Google Chrome etc...)

> WebDriver supports various programming languages to enhance Test cases.

> WebDriver supports various operating environments to create and execute Test cases(Ex: MS Windows, UNIX and Macintosh etc...)

> WebDriver supports Data Driven testing, cross browser testing.

> Webdriver is faster than other tools of Selenium suite.

> WebDriver supports Parallel test execution with the help of TestNG.

> WebDriver doesn't have IDE, only Programming interface.

> WebDriver doesn't have built in Result reporting facility, it provides summary only.(* with the help of TestNG we can generate HTML test reports.)

> No object Repository in selenium WebDriver (It is for entire Suite), so no centralized maintenance of Objects)

Using Element locators, Webdriver methods and Java programming features we can create and execute Test cases.

Element Locators - to recognize / identify Elements (Objects)

Webdriver Methods - to perform operations on Elements.

Java programming features - for Enhancing Test Cases.

Selenium Webdriver Environment Setup:

> Download and install Java (JDK) software - to enhance test cases using Java programming features.

> Set Path environment variable- to access Java from any directory.

> Download Eclipse IDE and extract

> Download WebDriver Java Language binding and add Webdriver jar files (in Eclipse)

>  Install Firebug and FirePath plug ins for Mozilla Firefox browser to inspect Elements.

Note 1: For Internet explorer and Google chrome, no need to install any plug ins, They have built in Developer tools.

Note 2: Element locators and WebDriver methods are common for all browsers, browser driver only varies from one browser to another.

Note 3: Firefox driver is default driver in Webdriver, For IE and Chrome we need to download drivers.

Download Selenium WebDriver Java binding from website and extract.

Navigation for adding Webdriver jar files in Eclipse.

> Create Java project

> Select src and right click

> Build path

> Configure Build Path

> select Libraries tab

> Click "Add External JARs

> Browser path of the WebDriver jars

> Add

Pre-requisites to Create Automated Tests / Test Scripts / Test Cases

> Import WebDriver Libraries and Firefox driver/IE driver/Chrome Driver

> Using Web Element (object) locators and WebDriver methods write object call statements

> Insert Java programmatic statements to enhance Test cases.

Element Locators 

Selenium supports 8 element locators to identify objects/elements on web pages.

We can use any one unique locator to identify elements.

1) id
2) name
3) classname
4) tagName
5) linkText
6) partialLinkText
7) cssSelector
8) xpath

IV) TestNG Framework

TestNG Introduction

> In Selenium using Java there are two Automation frameworks available:

i) JUnit

ii) TestNG

> TestNG is more powerful than JUnit framework.

> TestNG is an open source test automation framework, where NG stands for Next Generation

> TestNG inspired from JUNit but introduced some new functionality.

Benefits of TestNG:

> It generates HTML test reports

> TestNG Annotations are easy to create Test cases.

> Test cases can be grouped and prioritized more easily.

> Parallel Testing is possible

> Parameterization is possible.

Note: Using TestNG we can create Test cases, execute Test cases and generate reports in HTML format.

Install TestNG:

In Eclipse IDE,

Help menu -> Install New Software -> Click Add

-> Enter Name as "TestNG"

-> Enter URL as ""

-> Select TestNG

-> Next -> Next -> Accept the Agreement -> Finish

A Sample TestNG Program

public class SampleTest {
    public void verifyTitle()
    WebDriver driver = new FirefoxDriver();
    String Actual = driver.getTitle();
    Assert.assertEquals(Actual, "Gmail");
Create Multiple Test cases in a Program/Class

TestNG test cases can be executed in alphabetical order, if you want to control the Test execution then use Attributes.

public class SampleTest {
    public void testA()
    Assert.assertEquals("Google", "Google");
    public void testC()
    Assert.assertEquals("Gmail", "Google");
    public void testB()
    Assert.assertEquals("Yahoo", "Yahoo");
TestNG Annotations











V) Selenium IDE

Selenium IDE Introduction:

> Selenium IDE (Integrated Environment) is a Tool, used to develop Selenium Test Cases.

> It is Firefox plug in, works only on Firefox Browser.

> It provides Graphical user interface for Recording user actions using Firefox Browser.

> Firebug Add on is used to inspect elements.

> Selenium IDE should only be used as a prototyping tool.
Note: We can't develop complex Test cases using Selenium IDE.

Test Step in Selenium IDE Test Case

Test Step Syntax:

Command + Target + value

Command - forms the functionality of the Test step

Target - Identifies the Element on the web page.

Value - Input data (This applicable only for few commands)


Type     id=Email     abcd123

Download Install Selenium IDE

> Using Firefox browser, download selenium IDE from the website.

> Firefox will protect you from installing add ons from unfamiliar locations, so we  will need to click "Allow" to proceed with the installation.

> Install multiple items to support Java, Ruby, Python etc... formats.

> Restart Firefox browser.

> After Firefox reboots then we can use Selenium IDE.

Features of Selenium IDE

Using Selenium IDE, we can,

> Create Test cases and Test suites

> Open existing Test case

> Run Test case and Run Test suite.

> Export Test case in a Language of our choice.

> Debug Test cases.

> Add Comments, Insert verification points.

Drawbacks of Selenium IDE

> It supports Firefox Browser only, so cross browser testing is not possible.

> No Flow control statements (Conditions and Loops)

> Parametrization is not possible.

> Not suitable for creating complex Test cases.

> Doesn't provide detailed test reports, provides summary only.

> No Object Repository, so no centralized maintenance of Objects(Elements)

Create Test cases in Selenium IDE

By Recording Or Type steps using Selenese commands and element locators.

Difference between "assert" and "verify" Commands

> When an "assert" command fails then test execution will be aborted.

> When a "verify" command fails then test will continue execution and logging the failure.

VI) Selenium Grid 

Selenium Grid Introduction:

> Selenium Grid is part of the Selenium project.

> Using Selenium Grid we can distribute test execution across several machines.

> There are two main elements to Selenium Grid -- a hub, and nodes.

> First we need to stand up a hub, and then you can connect (or "register") nodes to that hub. Nodes are where your tests will run, and the hub is responsible for making sure your tests end up on the right one (e.g., the machine with the operating system and browser you specified).


Post a Comment