You are on page 1of 30

FRAMEWORK DOCUMENT

CONTENTS
1.What is Framework ?
2.Framework Architecture
3.Hybrid Framework
4.Difference b/w Common & Test Data
5.Generic Libraries
6.POM(Object Repository)
7.TestNG
8.Exceptions
9.Oops concept used in Framework
What is Framework ?
 Framework is a collection of reusable
components that makes automation
development and modification easier and
faster.
 It is a set of instruction followed by every

organization that makes automation test


engineer life easy.
Data
FRAMEWORK ARCHITECTURE
1.Common Pom.xml
Data Test Scripts
2.Script Dependencies
Data 1.Selenium
Test Test Test 2.Apache poi
case1 case2 case3 3.Testng
Generic Libraries 4.github
@Test
1.Properties
Utilities
2.Excel Utilities
Test Test Test HTML Reports
3.Java Utilities case4 case5 case6
4.WebDriver
Utilities
5.ReTryImpClass Used to
6.ListnerImpleme extends Pass Fail Skip
ntationClass
7.Base Class

Base Class If fails


Object Repository Take Screenshots
@BeforeSuite
@BeforeTest
@BeforeClass
@BeforeMethod Retry Failed
1.CampaignsPage @AfterSuite Testcases
2.ProductPage @AfterTest
@AfterClass
3.OrganizationsPage
@AfterMethod
4.SignOutPage
Jenkins Github
Hybrid Framework
 Our Framework is a hybrid framework Which is a
combination of TestNG,POM,Data Driven, Method
Driven.
 We execute the framework using testng.xml file,
which executes all the test class present in script
package.
 In our framework for every test case we create test
class with test method.
Advantages of Hybrid Framework
 Using a Hybrid frameworks leads to increased
code reusability, higher portability, reduced
cost of script maintenance, better code
readability.
 It needs to update only the test case file if

there is any change in the test case.


 the scripts will remain the same. Only we

have to choose the right framework


techniques to help in maintaining lower
costs.
Disadvantages of Framework
 Knowledge of automation testing is highly
required.
 One must have a very good programming

language in order to write test scripts.


Common Data & Test Data
 Common Data:-Data which is common to all the
test scripts is called as common data.
 Example:Browser,url,username,password(login
details of applications.)
 Test Data:- data that is specific to a test script is
called as test data.

 Example: Details like campaign name,product


name, organization name in application.
Generic Utilities: As per the rules of Automation data should not be hardcoded
Because hard coding the data in 1000 of test script becomes difficult to modify
Or maintain so instead of that data should be stored in one common package
Which makes modification and maintenance of data easy.

1.Java Utilities: Java Utility is one class in generic component, which contain java
specific methods which can be used across the test Scripts / Application
its contains several generic reusable methods like:-
getRandomNum() : It is used to generate random number for every invocation
in our test scripts.
2.WebDriver Utilities: Webdriver Utility is a Generic class , which contains
web driver specific reusable actions like:-

a.)waitForPageToLoad() After every action it will wait for the next action to
perform
b.)waitForElement() used to wait for element to be clickable in GUI and
check for specific element for every 500milliSeconds
c.)select() used to select value from drop down based on text, index etc.
d.)accpertAlert() Used to switch to alert window and accept(click on ok
button.
e.)cancelAlert() Used to switch to alert window and dismiss(click on cancel
button)
3. Excel Utility: As per the rule of automation, data should not be hardcoded
within the test scripts, so that to get the data from external file like Excel
& .properties file
We go for Excel Utility & FileUtlityExcel Utility class is developed using apache
Poi libraries, which is used to read the data from Excel File Utility is used to
get the data from .properties file .the file extension of excel should be .xlsx.

4. ListnerImplementationClass:It is a Implementated class of TestNG


ITestListener which is used for purpose of capturing the failed test script during
Execution time of multiple test scripts as a screen shot and store it in a folder
With .png as extension.

5.ReTryImpClass:It is an Implementation class of TestNG IRetryAnalyzer which is


Used execute same scripts multiple number of times whenever any test scripts
fails.
Advantages of DDT
 Maintenance of test data is easy.
 Modification of test data is easy.
 Cross browser testing is easy.
 Running test scripts in different environment

is easy.
 Reusing test scripts in different credential is

easy.
 Re running the same test script multiple

times with different data is easy.


POM(PAGE OBJECT MODEL)
 It’s a collection of elements locators & business libraries in one place & its
developed using POM design pattern.
 As per the rule of the automation, we should not hardcode[fixed]elements
within test Scripts instead, we should get elements from Object Repository ,
because in Agile process due to frequent requirement changes , modification
& maintenance of elements is tedious job.
 Object Repository:-In our Framework we have used this repository to store
elements, locators and business libraries in one place using the pom design
pattern rule.
 For every web pages we are having POM pages.
 Number of Web pages=Number of POM pages.
 In a POM page first we are creating a constructor with the same class name
and then with help of page factory we are initialing the element.
 We are passing (driver, this) inside page factory because this holds the
current address of the page and then that page gives control to driver to
perform action on that page.
POM Page Structure
 Initialization
 Declaration
 Getters Method
 Business logic
Initialization
Application level access
Constructor{
PageFactory.initElements(driver,this);
}

Current page access


POM Page

Page refresh
Initialize address

Address changes

StaleElementException
Declaration
@FindBy(LocatorName=‘Locator variable’)
Private WebElement ComponentName;

Business Logic
Public void username()
{
ComponentName.action
}
Annotations in POM
 All annotations are there in selenium
WebDriver.
 @FindBy(one locator/one condition):-Used to

identify the element based on one locator.


 @FindAll(Multiple locator):-Used to identify

same element using multiple locators. It uses


OR condition.
 @FindBys(Multiple locator):- Used to identify

same element using multiple locators. It uses


AND condition.
Advantages of Repository
 Reusability of elements, no need to write x-path &
other locators again & again.
 Modification in Repository is easy, when GUI changes

frequently.
 Maintenance is easy, because all the elements we

kept in one place(Package).


 Test Script Code Optimized via business reusable

libraries.
 More Readability.
 Test Script development is faster due to business lib.
 Handle Stale Elements Exception
Stale Elements Exception
 It’s one of selenium Exception , whenever web driver try to
identify an element , element was available in GUI, but at time
of performing an action on the elements element was not
recognized due to page got refreshed or elements may
become old or element not attached to page in such case we
get staleElementReferenceException.

 How to Handle Stale Elements Exception?

 Instead of FindElement() and FindElements() methods we are


using @FindBy() in our POM classes.
Advantages of POM
 Well organized structure.
 Handle stale element exception.
 maintains & modification of element is easy.
 We can directly store Web Elements in java

class.
 Better fit for Agile processes.
 Support Auto heal feature.
 Less complexity(Private access modifier).
What is Auto Healing(by using @FindAll) ?

 During execution if one locators fail to


identify the element then it will retry to
identify the same element using another
locator.
TestNG
 TestNG stands for testing next generation which is a unit testing tool
used by developers to perform white box testing.
 In my framework I have used TestNG in automating all the test cases
to test scripts.
 I have converted all my main methods to @Test because Without
@Test , TestNG class will not be executed, @test annotation method
act like main method in TestNG.
 I have also created a base class in which I have all annotations.
 My all test scripts are extended to base class.
 I have selected all my test scripts and converted them to testng.xml
 Now with help of testng.xml I have performed batch,parallel and
cross browser execution.
 Although JUNIT is a default plug-in in eclipse but I have used
TestNG.
Why TestNG but not JUNIT ?

JUNIT vs TestNG
Supports Supports

1.Annotation 1.HTML Report


2.Batch Execution 2.Batch Execution
3.Assertions 3.Parallel Execution
4.Group Execution
5.Additional Annotation
6.Cross Browser Execution
7.ITestListner
8.RetryAnalyser
9.Assertions
Base Class
 Base class contains @BeforeSuite,@BeforeTest etc which uses TestNG for test
execution of multiple of test scripts at a time.

 Annotation of TestNG

 ➔ @BeforeSuite:-It is used for Database Connection.


 ➔ @BeforeTest:- It is used to Execute script in parallel mode.
 ➔ @BeforeClass:- It is used for Launching the browser.
 ➔ @BeforeMethod:-It is used to Login to Application.
 ➔ @AfterMethod:- It is used to Logout to Application
 ➔ @AfterClass:- It is used for Closing the browser
 ➔ @AfterTest:- It is used when parallel execution is done
 ➔ @AfterSuite:- It is used when Database Connection is close
 ➔ @paramaters :- It is used for Cross browser execution
 ➔ @dataProvider :- It is used for different data.
 ➔ @Listner:- It is used to take screenshots.
Rules of TestNG
 1. Whenever we execute TestNG class, java Compiler always looks for @Test
Annotation method to start the execution.
 2. Without @Test , testNG class will not be executed, @test annotation
method act like main method in testNG
 3. In one TestNG class we can have multiple @test methods, but each test
method should have @Test annotation before method signature.
 4. Annotation method return type should be “void” and access specifier can
be public/private/protected/default., but method name can be anything (but
we have provide manual testNameTest).
 5. As per the Rule of the Automation , TESTNG class Name should be
ModuleNAme , @test method name should be manual testCase Name
 6. As per the Rule TestNG class Name & testNG method Name should end
With “Test”
 7. One Manual test case contains multiple steps all those steps should be
automated using one @test annotation & test name should be manual test-
case Name & end with Test
 8. In one class we can keep multiple @test annotation , but in real time we are
going maintain maximum 10 to 15 @test script , because maintenance will be
easy.
Advantages of TestNG

 With the help of TestNG We can run multiples of test scripts at a time
without any manual intimation.
 We can prioritize to test cases.
 We have to use @Test instead of main method.
 Without @Test , TestNG class will not be executed, @test annotation
method act like main method in testNG
 We can give invocation count
 We can use all annotations of TestNG in our base class.
 It Generate report automatically.
 We can do Parallel execution as well as cross browser execution.
 We can use Assertions for validation purpose
 We can re run failed test cases and took screenshot of failed test cases.
 Group execution helps us to segregate the test scripts into regression,
smoke testing.
 We can also test particular affect method using regional testing.
EXCEPTIONS
 Exceptions occurs during run time while execution of test
scripts
 It is a deviation in a normal flow.
 1.NoSuchElementException :If element is not found it will throw
this exception.
 2.TimeOutException :If element is not found it will throw this
exception.
 3.SeassionNotcreatedException : If chrome browser is updated
we will get this exception.
 4.NoAlertPresentException : when we try to click on both ok and
cancel button together then we will get this exception.
 5.NoSuchWindowException : This exception occurs if the window
target to be switch does not exist. it occurred when tried to
switch back from parent to child window.
 6.InvalidArgumentException : It occurs when an argument
does not belong to the expected type.(passing int to
String or vice versa found while using data provider).
 7.NullPointException : this exception occurs when the
application try to use an object reference which has a null
value.
 8.Unknown host exception :Mostly due to chrome driver
executable issues was resolved either by closing all the
running chrome sessions.
 9. elementnotinteractableexception : Thrown to indicate
that although a WebElement is present on the DOM, it is
not in a state that can be interacted with. This includes an
element that is not displayed or whose center point can
not be scrolled into the viewport.
OOPS Concept used in my Framework

 We have Polymorphism, Inheritance, Encapsulation and Abstraction in Oops.


So, we will start with
 1) DATA ABSTRACTION
 Data Abstraction means to handle complexity by hiding unnecessary details
from the user. In java, abstraction is achieved by interfaces and abstract
classes. We can achieve 100% abstraction using interfaces.
 In Selenium, WebDriver itself acts as an interface. Consider the below
statement:
 WebDriver driver = new ChromeDriver();
 We initialize the Chrome 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 ChromeDriver is a class.
 We can apply Data Abstraction in a Selenium framework by using the Page
Object Model design pattern. We define all our locators and their methods in
the page class. We can use these locators in our tests but we cannot see the
implementation of their underlying methods. So we only show the locators in
the tests but hide the implementation. This is a simple example of how we
can use Data Abstraction in our Automation Framework.
 2) ENCAPSULATION
 Encapsulation is defined as the wrapping up of data under a single unit. It is
the mechanism that binds together code and the data it manipulates.
Encapsulation can be achieved by: Declaring all the variables in the class as
private and writing public methods in the class to set and get the values of
variables.
 All the classes in an Automation Framework are an example of Encapsulation.
In Page Object Model classes, we declare the data members using @FindBy
and initialization of data members will be done using Constructor to utilize
those in methods.
 3) INHERITANCE
 Inheritance is the mechanism in java by which one class is allowed to inherit
the features (fields and methods) of another class.
 We can apply Inheritance in our Automation Framework by creating a Base
Class to initialize the WebDriver interface, browsers, waits, reports, logging,
etc. and then we can extend this Base Class and its methods in other classes
like Tests or Utilities. This is a simple example of how we can apply
Inheritance in our framework.
 4) POLYMORPHISM
 Polymorphism allows us to perform a single action in different ways. In Java
polymorphism can be achieved by two ways:
 – Method Overloading: When there are multiple methods with same name but
different parameters then these methods are said to be overloaded. Methods
can be overloaded by change in number of arguments or/and change in type
of arguments.
 Method overloading concept we have used in our WebDriver Utilities Class in
switch to frame methods, select methods with same name but different
parameters etc.
Thanks and Regards
 @Author VIKAS RAJAK

You might also like