Selenium Framework Explanation
Selenium Framework Explanation
Type of Framework:
In our project, we are using Data-driven Framework by using Page Object Model design
pattern with Page Factory.
POM: is an object design pattern in Selenium, where web pages are represented as
classes, and the various elements on the page are defined as variables on the class. All
possible user interactions can then be implemented as methods on the class
Packages: We have separate packages for Pages and Tests. All the web page related classes
come under Pages package and all the tests related classes come under Tests package.
For ex: Home Page and Login Page have a separate classes to store element locators. For
the login test there would be a separate class which calls the methods from the Home
Page class and Login Page class.
Test Base Class: Test Base class deals with all the common functions used by all the pages. This
class is responsible for loading the configurations from properties files, Initializing the
WebDriver, Implicit Waits, Extent Reports and also to create the object of FileInputStream
which is responsible for pointing towards the file from which the data should be read.
Utility Class: Utility class stores and handles the functions (The code which is repetitive in
nature such as waits, actions, capturing screenshots, accessing excels, sending email etc.,)
which can be commonly used across the entire framework. The reason behind creating utility
class is to achieve reusability.
Properties file: This file stores the information that remains static throughout the framework
such as browser specific information, application URL, screenshots path etc. All the details
which change as per the environment and authorization such as URL, Login Credentials are kept
in the config.properties file. Keeping these details in a separate file makes easy to maintain.
Screenshots: Screenshots will be captured and stored in a separate folder and also the
screenshots of a failed test cases will be added in the extent reports.
Test Data: All the historical test data will be kept in excel sheet (controller.xlsx). By
using ‘controller.xlsx’, we pass test data and handle data driven testing. We use Apache POI to
handle excel sheets.
Maven: We used maven for building, executing and dependency purpose. Integrating the
TestNG dependency in POM.xml file and running this POM.xml file using Jenkins/GitLab.
TestNG: running all the tests at the same time like regression, smoke test scripts, for that
reason we are using TestNG. This also helps to achieve parallel and group execution.
Version Control: We are using GIT for storing all the scripts at a centralized repository.
Jenkins: By using Jenkins CI (Continuous Integration) Tool, we execute test cases on daily basis
and also for nightly execution based on the schedule. Test Result will be sent to the peers using
Jenkins.
Extent Reports: For the reporting purpose, we are using Extent Reports. It generates beautiful
HTML reports. We use the extent reports for maintaining logs and also to include the
screenshots of failed test cases in the Extent Report.
What is a Framework?
A framework defines a set of rules or best practices which we can follow in a systematic way to
achieve the desired results.
Tell me some popular Test Automation Frameworks?
There are different types of test automation frameworks and the most common ones are:
Modular Testing Framework
Data Driven Testing Framework
Keyword Driven Testing Framework
Hybrid Testing Framework
Behavior Driven Development Framework
INTERFACE
An interface in Java looks similar to a class but both the interface and class are two different
concepts. An interface can have methods and variables just like the class but the methods
declared in interface are by default abstract. We can achieve 100% abstraction and multiple
inheritance in Java with Interface.
In Selenium WebDriver driver = new FirefoxDriver();
WebDriver itself is an Interface. we are initializing Firefox browser using Selenium WebDriver.
It means we are creating a reference variable (driver) of the interface (WebDriver) and creating
an Object. Here WebDriver is an Interface and FirefoxDriver is a class.
INHERITANCE
Extending one class into other class is known as Inheritance.
We create a Base Class in the Framework to initialize WebDriver interface, WebDriver waits,
Property files, Excels, etc., in the Base Class. We extend the Base Class in other classes such as
Tests and Utility Class.
POLYMORPHISM
Polymorphism allows us to perform a task in multiple ways. Combination of overloading and
overriding is known as Polymorphism.
METHOD OVERLOADING
A class having multiple methods with same name but different parameters is called Method
Overloading
We use implicit wait in Selenium. Implicit wait is an example of overloading. In Implicit wait we
use different time stamps such as SECONDS, MINUTES, HOURS etc.
METHOD OVERRIDING
Declaring a method in child class which is already present in the parent class is called Method
Overriding. Examples: get and navigate methods of different drivers in Selenium.
ENCAPSULATION
Encapsulation is a mechanism of binding code and data together in a single unit.
All the classes in a framework are an example of Encapsulation. In POM classes, we declare the
data members using @FindBy and initialization of data members will be done using Constructor
to utilize those in methods.