SlideShare a Scribd company logo
Page object pattern
Konopelko Petro
Page object pattern
Page object pattern
Problems
● Obscure tests (непонятный тест)
● Fragile tests (хрупкий тест)
● Bad maintainability (плохая поддерживаемость)
● It’s hard to develop new tests (сложно разрабатывать новые тесты)
● Test code duplication (дублирование тестового кода)
● Frequent manual intervention (частое ручное вмешательство)
● High cost maintenance test (высокая стоимость поддержки)
Page Object
I’ll clean it
There could
be your ad
Test appearance with Page object pattern
Page Object pattern
The PageObject Design Pattern models areas of an UI as objects within test code which
can also be considered as Object Repository for Web UI Elements. The functionality classes
(PageObjects) in this design represent a logical relationship between the pages of the
application. Each class is referred to as a PageObjects and returns other PageObjects to
facilitate the flow between pages. Page Object class is responsible to find the WebElements
of that page and also hold methods which perform operations on those WebElements.
By click on
Sign in button
Create an account page is opened
Forgot password page
is opened
Base principle Page Object pattern
● The public methods represent the services that the page offers
● Try not to expose the internals of the page
2)There is no private _userNameElement in the Intellisense.
1)You can’t have access to the element due to its protection level.
Base principle Page Object pattern
● Methods return other PageObjects
● Different results for the same action are modelled as different methods
● Generally Don't make assertions
Huge pages and page elements
Category block
Main news block
News item list
Scoreboard
Weather forecast
Page Factory
The PageFactory in C# Class is an extension to the Page Object Design Pattern. It is used to
initialize the elements of the Page Object or instantiate the Page Objects itself.
It is used to Initialize Elements of a Page class without having to use ‘FindElement‘ or
‘FindElements‘. Annotations can be used to supply descriptive names of target objects to improve
code readability.
● If you use the PageFactory, you can assume
that the fields are initialised. If you don't use the
PageFactory, then NullPointerExceptions will be
thrown if you make the assumption that the
fields are already initialised.
● WebElements are evaluated lazily. That is, if you
never use a WebElement field in a PageObject,
there will never be a call to "findElement" for it.
NullPointerException
if you do not initialize
Factory
Page Factory - FindsBy attributes
● [FindsBy]
● [FindsByAll]
● [FindsBySequence]
Will find the element with the ID
attribute matching "elementId", then will
find a child element with the ID attribute
matching "childElementId"
Will find the element with the name
attribute matching the first of "firstname" or
"secondName"
Will find the element with the tag
name "input" that also has an ID attribute
matching "elementId".
CacheLookup
PageFactory provide CacheLookup attribute to cache the WebElements. This attribute helps
scripts to instruct the InitElements method to cache the element once it's located. In other words, any
attribute marked [CacheLookup] will not be searched over and over again – this is especially useful for
elements that are always going to be there (not always true for AJAX apps). It means the elements of
the page will be cached once searched
But when you use the CacheLookup annotation, it will
find the element once and then keep a reference to it, you
are now far more likely to see StaleElementExceptions.
➢ Without cacheLookup
Every time you use a WebElement it will go and find it
again so you shouldn’t see StaleElementException’s.
➢ With cacheLookup
CacheLookup performance
Without CacheLookup, ms With CacheLookup, ms
Click, 100 iterations 6359 4838
SendKeys,100 iterations 19932 17263
GetText, 100 iterations
2583 1406
Tool
➢ Page object generator(Chrome and Opera extension)
Name of current page
Name of returning page
Programming language(C#, Java,
Robot Framework)
References
1. Page Objects from Selenium
2. Page Factory from Selenium
3. Page object (russian)
4. Page Object, Page factory by toolsqa
5. Page object pattern by Martin Fowler
6. Code example from slides for Git Hub on Git Hub
Just a joke =)

More Related Content

PDF
Page Object Model and Implementation in Selenium
PDF
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...
PPTX
Setting up Page Object Model in Automation Framework
PPT
Selenium Automation Framework
PDF
Selenium - Introduction
PDF
Kiss PageObjects [01-2017]
PPTX
Automation - web testing with selenium
PPT
Introduction to JavaScript (1).ppt
Page Object Model and Implementation in Selenium
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...
Setting up Page Object Model in Automation Framework
Selenium Automation Framework
Selenium - Introduction
Kiss PageObjects [01-2017]
Automation - web testing with selenium
Introduction to JavaScript (1).ppt

What's hot (20)

PPTX
Angular Unit Testing
PPT
Hybrid framework
PDF
Web automation using selenium.ppt
PPT
Test Automation Framework Designs
PPTX
Automation Testing by Selenium Web Driver
PDF
Unit Testing in Angular
PPTX
Test Automation and Selenium
PPTX
Angular Unit Testing
PPTX
Unit Testing And Mocking
PPT
Selenium
PPTX
Javascript 101
PPTX
Hybrid automation framework
PPS
JUnit Presentation
PPSX
Selenium WebDriver
PDF
Test Automation Frameworks Using Selenium | Edureka
PDF
PPTX
TestNG with selenium
PDF
Web application testing with Selenium
PPT
QSpiders - Automation using Selenium
Angular Unit Testing
Hybrid framework
Web automation using selenium.ppt
Test Automation Framework Designs
Automation Testing by Selenium Web Driver
Unit Testing in Angular
Test Automation and Selenium
Angular Unit Testing
Unit Testing And Mocking
Selenium
Javascript 101
Hybrid automation framework
JUnit Presentation
Selenium WebDriver
Test Automation Frameworks Using Selenium | Edureka
TestNG with selenium
Web application testing with Selenium
QSpiders - Automation using Selenium
Ad

Similar to Page object pattern (20)

PPTX
Out of box page object design pattern, java
PPTX
Beyond pageobjects
PDF
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...
PPTX
Better Page Object Handling with Loadable Component Pattern
PPTX
Out of box page object design pattern, java
PDF
PageObject
PDF
Automation strategies for agile testing Gaurav bansal
PPTX
Selenium Design Patterns
PPTX
Page Fragments как развитие идеи Page Object паттерна
PDF
Page Objects - You're Doing it Wrong by Titus Fortner
PPTX
Using Page Objects
PPTX
JavaScript front end performance optimizations
PDF
Perils of Page-Object Pattern
PDF
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
PDF
Design Patterns for QA Automation
PDF
Using The Page Object Pattern
PPTX
Common ASP.NET Design Patterns - Telerik India DevCon 2013
PDF
jQuery - 10 Time-Savers You (Maybe) Don't Know
PDF
Ad109 - XPages Performance and Scalability
PDF
Advanced guide to develop ajax applications using dojo
Out of box page object design pattern, java
Beyond pageobjects
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...
Better Page Object Handling with Loadable Component Pattern
Out of box page object design pattern, java
PageObject
Automation strategies for agile testing Gaurav bansal
Selenium Design Patterns
Page Fragments как развитие идеи Page Object паттерна
Page Objects - You're Doing it Wrong by Titus Fortner
Using Page Objects
JavaScript front end performance optimizations
Perils of Page-Object Pattern
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Design Patterns for QA Automation
Using The Page Object Pattern
Common ASP.NET Design Patterns - Telerik India DevCon 2013
jQuery - 10 Time-Savers You (Maybe) Don't Know
Ad109 - XPages Performance and Scalability
Advanced guide to develop ajax applications using dojo
Ad

Recently uploaded (20)

PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
Cell Structure & Organelles in detailed.
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
01-Introduction-to-Information-Management.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Classroom Observation Tools for Teachers
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
master seminar digital applications in india
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
human mycosis Human fungal infections are called human mycosis..pptx
Basic Mud Logging Guide for educational purpose
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Cell Structure & Organelles in detailed.
Renaissance Architecture: A Journey from Faith to Humanism
Module 4: Burden of Disease Tutorial Slides S2 2025
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
01-Introduction-to-Information-Management.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Microbial diseases, their pathogenesis and prophylaxis
Final Presentation General Medicine 03-08-2024.pptx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Classroom Observation Tools for Teachers
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
master seminar digital applications in india
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
2.FourierTransform-ShortQuestionswithAnswers.pdf

Page object pattern

  • 4. Problems ● Obscure tests (непонятный тест) ● Fragile tests (хрупкий тест) ● Bad maintainability (плохая поддерживаемость) ● It’s hard to develop new tests (сложно разрабатывать новые тесты) ● Test code duplication (дублирование тестового кода) ● Frequent manual intervention (частое ручное вмешательство) ● High cost maintenance test (высокая стоимость поддержки)
  • 5. Page Object I’ll clean it There could be your ad
  • 6. Test appearance with Page object pattern
  • 7. Page Object pattern The PageObject Design Pattern models areas of an UI as objects within test code which can also be considered as Object Repository for Web UI Elements. The functionality classes (PageObjects) in this design represent a logical relationship between the pages of the application. Each class is referred to as a PageObjects and returns other PageObjects to facilitate the flow between pages. Page Object class is responsible to find the WebElements of that page and also hold methods which perform operations on those WebElements. By click on Sign in button Create an account page is opened Forgot password page is opened
  • 8. Base principle Page Object pattern ● The public methods represent the services that the page offers ● Try not to expose the internals of the page 2)There is no private _userNameElement in the Intellisense. 1)You can’t have access to the element due to its protection level.
  • 9. Base principle Page Object pattern ● Methods return other PageObjects ● Different results for the same action are modelled as different methods ● Generally Don't make assertions
  • 10. Huge pages and page elements Category block Main news block News item list Scoreboard Weather forecast
  • 11. Page Factory The PageFactory in C# Class is an extension to the Page Object Design Pattern. It is used to initialize the elements of the Page Object or instantiate the Page Objects itself. It is used to Initialize Elements of a Page class without having to use ‘FindElement‘ or ‘FindElements‘. Annotations can be used to supply descriptive names of target objects to improve code readability. ● If you use the PageFactory, you can assume that the fields are initialised. If you don't use the PageFactory, then NullPointerExceptions will be thrown if you make the assumption that the fields are already initialised. ● WebElements are evaluated lazily. That is, if you never use a WebElement field in a PageObject, there will never be a call to "findElement" for it. NullPointerException if you do not initialize Factory
  • 12. Page Factory - FindsBy attributes ● [FindsBy] ● [FindsByAll] ● [FindsBySequence] Will find the element with the ID attribute matching "elementId", then will find a child element with the ID attribute matching "childElementId" Will find the element with the name attribute matching the first of "firstname" or "secondName" Will find the element with the tag name "input" that also has an ID attribute matching "elementId".
  • 13. CacheLookup PageFactory provide CacheLookup attribute to cache the WebElements. This attribute helps scripts to instruct the InitElements method to cache the element once it's located. In other words, any attribute marked [CacheLookup] will not be searched over and over again – this is especially useful for elements that are always going to be there (not always true for AJAX apps). It means the elements of the page will be cached once searched But when you use the CacheLookup annotation, it will find the element once and then keep a reference to it, you are now far more likely to see StaleElementExceptions. ➢ Without cacheLookup Every time you use a WebElement it will go and find it again so you shouldn’t see StaleElementException’s. ➢ With cacheLookup
  • 14. CacheLookup performance Without CacheLookup, ms With CacheLookup, ms Click, 100 iterations 6359 4838 SendKeys,100 iterations 19932 17263 GetText, 100 iterations 2583 1406
  • 15. Tool ➢ Page object generator(Chrome and Opera extension) Name of current page Name of returning page Programming language(C#, Java, Robot Framework)
  • 16. References 1. Page Objects from Selenium 2. Page Factory from Selenium 3. Page object (russian) 4. Page Object, Page factory by toolsqa 5. Page object pattern by Martin Fowler 6. Code example from slides for Git Hub on Git Hub