0% found this document useful (0 votes)
26 views7 pages

Selenium WebDriver Basics and Setup

The document discusses Selenium WebDriver. It begins with an overview of basic Java concepts like inheritance, polymorphism, abstraction and encapsulation. It then provides an introduction to Selenium, explaining what it is used for, its different flavors, supported languages and browsers. Finally, it details the architecture of Selenium WebDriver, including software requirements and examples of sample programs to launch Firefox, Chrome and Internet Explorer browsers.

Uploaded by

siva sanniboina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views7 pages

Selenium WebDriver Basics and Setup

The document discusses Selenium WebDriver. It begins with an overview of basic Java concepts like inheritance, polymorphism, abstraction and encapsulation. It then provides an introduction to Selenium, explaining what it is used for, its different flavors, supported languages and browsers. Finally, it details the architecture of Selenium WebDriver, including software requirements and examples of sample programs to launch Firefox, Chrome and Internet Explorer browsers.

Uploaded by

siva sanniboina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

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

[Link]

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)

[Link]

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 [[Link]]

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

[Link]("[Link]
Q: How does “new Firefox Driver ()” statement is opening the “Firefox” browser?

Firefox driver is included in the [Link] 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 “[Link]” file from [Link] website or


[Link]

2. Set System Property as:

[Link](“[Link]”, “<Location of chromedriver file>”)

3. WebDriver driver= new ChromeDriver ();

Steps to execute on IE:

1. Download “[Link]” file from [Link] website or [Link]


[Link]/[Link]

2. Set System Property as:

[Link](“[Link]”, “<Location of IEDriver file>”)

3. WebDriver driver= new InternetExplorerDriver ();

Common questions

Powered by AI

Browser compatibility significantly impacts Selenium test execution since rendering differences between browsers can lead to inconsistent test results. Ensuring cross-browser consistency requires thorough testing across all supported browsers, such as Chrome, Firefox, and Internet Explorer, and adapting tests to account for each browser's quirks. Using WebDriver's capabilities, such as setting browser-specific parameters, is essential for consistent test execution across different environments .

Setting up Selenium WebDriver requires software components like JDK, an IDE such as Eclipse, Selenium Standalone JARs, and browser executables like ChromeDriver and IEDriver. Challenges include ensuring compatibility between these components, such as matching JDK versions with Eclipse, maintaining updated browser drivers, and handling network restrictions for downloading necessary files. These requirements demand careful environment management to avoid integration issues that could lead to test failures .

Selenium WebDriver's architecture directly communicates with web browsers, eliminating the need for an intermediary server, which was necessary for Selenium RC. This simplification reduces software requirements, as WebDriver operates using simpler protocol specifications suited to specific browsers. Consequently, execution speed sees significant improvements because it reduces network latency and resource overhead, allowing faster, more reliable execution of tests .

Java's inheritance facilitates test automation framework design by allowing the creation of a hierarchy of reusable classes. In test automation, a base class often includes common test methods and configurations that can be inherited by multiple derived test classes. This leads to reduced code duplication and enhanced maintainability, as updates to the base class automatically propagate to all derived classes .

Exception handling in Selenium is crucial for maintaining test reliability, as unhandled exceptions can cause test runs to fail unexpectedly, leading to unreliable results. Unchecked exceptions, such as NullPointerException, occur at runtime and need to be addressed to prevent abrupt test failures. Checked exceptions, such as IOException, are detected at compile time, and managing them ensures that the test environment variables are correctly set, reducing the risk of environmental issues affecting test runs .

Selenium IDE is a record-and-playback tool that is easy to use for beginners but limited in functionality and flexibility. Selenium RC (Remote Control) provides more robust options by allowing users to write automated tests in various programming languages, but it is slower and more complex due to its server-dependent architecture. Selenium WebDriver, the most current version, eliminates the need for a server and offers faster, more direct interaction with browsers. WebDriver supports modern browsers and complex scenarios better, impacting its use by making it the preferred choice for comprehensive test automation .

Upcasting in Selenium involves casting specific WebDriver instances to the WebDriver interface, allowing seamless switching between different browser drivers, thereby providing significant script flexibility. Downcasting, though less commonly used, can be necessary for accessing specific methods of a particular driver class. While upcasting generally enhances script versatility, downcasting can lead to less flexible code and potential runtime exceptions if not managed carefully .

Abstraction in Selenium involves using abstract classes and interfaces to define methods without implementing them, allowing users to focus on writing only the necessary code for specific test cases. Encapsulation is used by making instance variables of a class private and providing public getter and setter methods. This approach aids in maintaining the robustness and maintainability of test scripts by hiding unnecessary complexity and enhancing clarity and structure .

The choice of programming language in Selenium affects its functionality through language-specific features like syntax, libraries, and tools that can influence test development and maintenance. For instance, using Java might offer broad community support and powerful libraries, while Python may provide quicker development due to its simpler syntax. Integration into different testing environments requires language compatibility with existing developer tools and frameworks, impacting the ease and speed of test deployment .

Polymorphism in Selenium is crucial for executing tests across different browsers, as it allows the use of a common interface (WebDriver) to control different browser instances like FirefoxDriver, ChromeDriver, and InternetExplorerDriver. This capability is essential because it enables writing code that is browser-independent, enhancing test script maintainability and reducing redundancy .

You might also like