Selenium WebDriver
Session: 1
Topics:
# Subject name
1 Overview of basic Java concepts
Inheritance, Polymorphism, Abstraction,
Encapsulation
Upcasting, Downcasting
Exceptions and its Types
2 Introduction to Selenium
Why Selenium?
Different flavors of Selenium
Latest Selenium version
Languages supported by Selenium
Browser supported by Selenium
seleniumhq.org
3 Architecture of Selenium WebDriver
Hardware and Software requirements to setup
Selenium
A sample selenium program to be executed on
Firefox browser
4 sample selenium program to be executed on
Chrome browser
sample selenium program to be executed on IE
browser
1. Overview of Overview of basic Java concepts
Inheritance:
A class deriving the properties of another class is called Inheritance.
Super class (Parent) and Sub class (Child)
Types of Inheritance: Single, Multi- Level and Hierarchal
Constructor: Default constructor, User defined no- parameter constructor and User defined
Parameter constructor
Polymorphism:
State of taking different forms based on the input given
Types: Static Polymorphism (Method Overloading/ Compile time/ Early binding), Dynamic
Polymorphism (Method Overriding/ Runtime/ Late binding)
Upcasting and Downcasting
All objects in Java are said to polymorphic because any class object in java can be stored using
object class instance variable.
Abstraction:
Process of hiding the business logic and allowing the users to use the functionality
Achieved using Abstract classes and Interfaces
Encapsulation:
Binding the variables using “private” access specifier and providing “public getters and setters”
method to access them
Mainly used in POM classes of TestNG
Exceptions and its Types
Unexpected event occurring during the course of program execution
Exceptions can be handled and need to be handled.
Exceptions are classified into 2 types:
o Runtime Exception (Unchecked Exceptions) Ex: ArrayIndexOutOfBoundException,
NullPointerException, ArithmaticException, claasCastException,
TypeMismatchException, InputMismatchException
o Compile time Exception (Checked Exception) Ex: ClassNotFoundException,
SQLException, IOException, interruptedException, FileNotFoundException
2. Introduction to Selenium
Selenium:
Automation tool used to test web based application (any application which can be run on a
browser) automatically.
Cannot be used for Window based application.
Selenium is basically not a tool. We will configure Eclipse tool to work as Selenium using
Selenium standalone jars
Why Selenium?
Nowadays most of the window based applications took transition towards web based
applications. Hence the scope of testing the web based application increased
There are many tools in market to test web applications which includes QTP, Silk test tool etc.
Selenium also one of the web testing tool which is an open source tool which supports multiple
browsers and provides multi language support.
Different flavors of Selenium
1. Selenium IDE
2. Selenium RC (Remote Control)
3. Selenium WebDriver (Currently used)
Languages supported by Selenium
Java, C#, Ruby, Python, Java Script, Perl, PHP
Browser supported by Selenium
Mozilla Firefox (Default Support), Google Chrome, Internet Explorer, Opera, Safari and Microsoft Edge
(Most recently supported)
seleniumhq.org
Official website for Selenium
Here we can find all Selenium related documentation, required jar files, executables required for other
browsers and many more.
Latest Selenium Jar file version
Selenium Standalone Jars: 3.4.0
3. Architecture of Selenium WebDriver
Software requirements to setup Selenium
1. JDK [Java 8 131 update]
2. Eclipse / Netbeans [Version: Mars.2 Release (4.5.2) Build id: 20160218-0600]
3. Selenium Standalone Jars [selenium-java-2.53.0.jar]
4. Mozilla Firefox browser [46.0.1]
5. ChromeDriver and IEDriver executables (Optional)
4. Eclipse and Selenium standalone jars:
Eclipse:
1. As soon as the eclipse is opened the below dialog is displayed to choose the required workspace
[Note: Workspace is the place where user’s Java programs will be stored]
2. Create any folder in the required drive say “SeleniumSession” folder is created in “C” drive
3. Click on browse and select “SeleniumSession” folder [so Workspace location is: C:\
SeleniumSession]. Click OK; Eclipse opens
4. Click “File-> Java Project” and specify any name [Ex: SeleniumSession as shown below]. “src” and
“JRE System Library” folder is displayed as shown below
Note: Ensure that the Java related files are present under “JRE System Library” folder as shown above.
Selenium Standalone Jars:
To associate Selenium Standalone jars, Follow the below steps
1. Right click on the Java project folder [Ex: SeleniumSession] and select “Properties” option; “Java
Build Path” is displayed as shown below
2. Click on “Add External JARs..” button and select the “Selenium Standalone jars” and additional
jars present in the libs folder of “Selenium Jar” folder
3. Click “Apply”; “OK” to close
4. Create a new Package with any name [Ex: SeleniumPractice]
5. Create a new class say: Session1 and write the below lines of code
Selenium Program to open Firefox browser
WebDriver driver = new FirefoxDriver();
Selenium program to open “Google” website in Firefox
driver.get("http://www.google.com");
Q: How does “new Firefox Driver ()” statement is opening the “Firefox” browser?
Firefox driver is included in the selenium-server-stanalone.jar available in the downloads. The driver
comes in the form of an xpi (Firefox extension) which is added to the Firefox profile when you start a
new instance of Firefox Driver.
Q: Why do we need to upcast to “WebDriver”?
To run the script on different browsers
While Upcasting it is always recommended to upcast to the highest level without losing any
unimplemented methods
Executing on IE and Chrome browser
Steps to execute on Chrome:
1. Download “ChromeDriver.exe” file from seleniumhq.org website or
http://chromedriver.storage.googleapis.com/index.html
2. Set System Property as:
System.setProperty(“webdriver.chrome.driver”, “<Location of chromedriver file>”)
3. WebDriver driver= new ChromeDriver ();
Steps to execute on IE:
1. Download “ieDriverServer.exe” file from seleniumhq.org website or http://selenium-
release.storage.googleapis.com/index.html
2. Set System Property as:
System.setProperty(“webdriver.ie.driver”, “<Location of IEDriver file>”)
3. WebDriver driver= new InternetExplorerDriver ();