SlideShare a Scribd company logo
Page Fragments
OR PAGE ELEMENTS
OR HTML ELEMENTS
OLEKSANDR KHOTEMSKYI
http://xotabu4.github.io
EXTENDING IDEAS OF PAGE OBJECTS PATTERN
In this presentation
1. Quick explanation of modern Page Objects
2. Idea of Page Fragments
3. What this gives to us?
4. Code examples
Quick explanation of
modern Page Objects
Page Fragments как развитие идеи Page Object паттерна
Idea of page
object
• Based on OOP principles
• One class describes one page
• Pages can inherit one from
another
• Additional layer of abstraction
for our tests
• Extracts elements
manipulations from test logic
Page
Notes
RecycleBin
Archive
createNote (title, body) {}
deleteNote (index) {}
archiveNote (index) {}
changeNoteColor (index, color) {}
editNote (index, title, body) {}
deleteNoteForever (index) {}
restoreNote (index) {}
unarchiveNote (index) {}
deleteNote (index) {}
changeNoteColor (index, color) {}
editNote (index, title, body) {}
openRecycleBinPage()
openArchivePage()
openNotesPage()
Idea of page
object
• Elements are belongs to
object instance, usually as
class fields or instance
attribute
• Elements should be
initialized in proper time
• Methods describe actions
that user can do on the page
NotesPage
headerMenuButton
openRecycleBinPageLink
openArchivePageLink
openNotesPageLink
createNoteField
deleteNoteButtons
archiveNoteButtons
changeColorButtons
…
Best practices
• Page object methods should do
only what specified in their
name
• This means not less than needed
to make action completed, not
more than needed to make
action completed
• Use inheritance, composition,
use reliable locators, chain
searching of elements
• If you have repeatable complex
actions in your tests – use
models to reduce copy-paste
Page Fragments
Modern apps consist of different components
Idea of
Fragments
• Reproduce the same structure of
objects on the page that we
already have in our application
• Now page is not the smallest
object in framework
• Break fragments into smaller
fragments
• Group smaller fragments into
bigger fragments
• Reuse methods of child fragments
in parent fragment
NoteFragment
INCLUDES fragments:
ArchiveButton
ChangeColorButton
DeleteButton
getTitle()
getBody()
edit(title, body)
changeColor(color)
delete()
archive()
Fragments
• Use chaining for elements
search where possible
• Search inside element
instead searching
everywhere on the page
• As an option, pass root
element into constructor
as parameter, and use it
to make all searches
inside this element
let deleteButton = browser.element(by.css('button.delete'))
Better:
Bad:
Idea of
Fragments
• Inherit one fragment from
another
• Use power of OOP
• Introduce types in
languages without strict
types (JS, Python) to
enable autocomplete in
IDE
• Use interfaces, abstract
classes to introduce
parent objects
NoteFragment
ArchivedNoteFragment
DeletedNoteFragment
AbstractNoteFragment
???
Fragment
Experimental features
Custom
collections of
own fragments
• Create custom collections with
your fragments
• Works like usual array/list/etc , but
extended with your own methods
• Iterate thru collection, apply filters
• Best works for things like search
results
• Feature state:
• Java – tested and used in prod
• Python – not investigated (3rd party
libs exists)
• JS (ProtractorJS) – testing and bug
fixing
NotesArrayFragment
get(index) -> returns NoteFragment
count()
map()
filter()
…
hasNoteWithTitle(title)
hasNoteWithTitle(body)
hasNoteWithColor(title)
Inherit from
WebElement
object
• Your fragments now valid
WebElements
• Your custom fragments can be
passed to any methods that
require WebElement as parameter
• Override existing WebElement
methods, such as isDisplayed() for
even more flexibility (if needed)
WebElement
Object
Inheritance
chain
FooFragment
BarFragment
What this gives to us?
Benefits
• Nice reusing of components across
different pages or even projects
• Better stability on locators changes
• Logic spited across smaller parts –
easier to change
• Cleaner code
• Easier to understand because
everything has it own names
• Can be applied to any
tool/programming language. Also
works for non-web applications
Hard parts
• Requires good understanding of
OOP principles
• Requires to write more code
• Might be not needed in tiny
projects – best works in
applications with a lot of similar
fragments
• Idea is not used widely. Everyone
building own approach
• Additional framework layer in
your code
Code examples
PROTRACTOR + TYPESCRIPT
Page Fragments как развитие идеи Page Object паттерна
Page Fragments как развитие идеи Page Object паттерна
Page Fragments как развитие идеи Page Object паттерна
Page Fragments как развитие идеи Page Object паттерна
Page Fragments как развитие идеи Page Object паттерна
Page Fragments как развитие идеи Page Object паттерна
Page Fragments как развитие идеи Page Object паттерна
Page Fragments как развитие идеи Page Object паттерна
Page Fragments как развитие идеи Page Object паттерна
Page Fragments как развитие идеи Page Object паттерна
Now it is time to ask questions
https://github.com/Xotabu4/protractor-element-extend
http://xotabu4.github.io/

More Related Content

PDF
Get the most out of Solr search with PHP
PPTX
Java and SPARQL
PDF
PDF
Few simple-type-tricks in scala
PPTX
Learning Web Development with Django - Templates
PPTX
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javac
PPTX
Solr Introduction
PPTX
Java and XML
Get the most out of Solr search with PHP
Java and SPARQL
Few simple-type-tricks in scala
Learning Web Development with Django - Templates
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javac
Solr Introduction
Java and XML

What's hot (20)

PDF
it's just search
PDF
Lucene for Solr Developers
PPTX
Examiness hints and tips from the trenches
PDF
Building your own search engine with Apache Solr
PPTX
ElasticSearch, Elastica, ElasticaBundle
PPTX
06.1 .Net memory management
PPTX
02 beginning code first
PDF
Improving Top-K Retrieval Algorithms Using Dynamic Programming and Longer Ski...
PDF
Integrating the Solr search engine
PDF
code4lib 2011 preconference: What's New in Solr (since 1.4.1)
PDF
Delving (Smalltalk) Source Code
PDF
Ponies and Unicorns With Scala
PPTX
Jena Programming
PPT
Python first day
PPT
Python first day
PPTX
Battle of the giants: Apache Solr vs ElasticSearch
PDF
Elasticsearch and Symfony Integration - Debarko De
PDF
Information Retrieval - Data Science Bootcamp
PPTX
OCAS @ ISWC 2011 - Generic Multilevel Approach Designing Domain Ontologies Ba...
PPT
070517 Jena
it's just search
Lucene for Solr Developers
Examiness hints and tips from the trenches
Building your own search engine with Apache Solr
ElasticSearch, Elastica, ElasticaBundle
06.1 .Net memory management
02 beginning code first
Improving Top-K Retrieval Algorithms Using Dynamic Programming and Longer Ski...
Integrating the Solr search engine
code4lib 2011 preconference: What's New in Solr (since 1.4.1)
Delving (Smalltalk) Source Code
Ponies and Unicorns With Scala
Jena Programming
Python first day
Python first day
Battle of the giants: Apache Solr vs ElasticSearch
Elasticsearch and Symfony Integration - Debarko De
Information Retrieval - Data Science Bootcamp
OCAS @ ISWC 2011 - Generic Multilevel Approach Designing Domain Ontologies Ba...
070517 Jena
Ad

Similar to Page Fragments как развитие идеи Page Object паттерна (20)

PPTX
Java scriptforjavadev part2a
PPT
Eclipse Day India 2011 - Extending JDT
PPTX
JS Essence
PDF
Advanced guide to develop ajax applications using dojo
PPTX
Web scraping using scrapy - zekeLabs
PDF
Apache Calcite (a tutorial given at BOSS '21)
PPTX
Effiziente persistierung
PDF
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
PDF
How to train the jdt dragon
PDF
SQLGitHub - Access GitHub API with SQL-like syntaxes
PPTX
Angular JS
PPTX
Ajaxworld
PPTX
Session 14 - Object Class
PPTX
oop 3.pptx
PDF
Ejb3 Struts Tutorial En
PDF
Ejb3 Struts Tutorial En
PDF
Full Text Search In PostgreSQL
PDF
TDD with phpspec2
PDF
Introduction to Python and Django
PPSX
Object Class
Java scriptforjavadev part2a
Eclipse Day India 2011 - Extending JDT
JS Essence
Advanced guide to develop ajax applications using dojo
Web scraping using scrapy - zekeLabs
Apache Calcite (a tutorial given at BOSS '21)
Effiziente persistierung
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
How to train the jdt dragon
SQLGitHub - Access GitHub API with SQL-like syntaxes
Angular JS
Ajaxworld
Session 14 - Object Class
oop 3.pptx
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial En
Full Text Search In PostgreSQL
TDD with phpspec2
Introduction to Python and Django
Object Class
Ad

Recently uploaded (20)

PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
medical staffing services at VALiNTRY
PPTX
Transform Your Business with a Software ERP System
PPTX
L1 - Introduction to python Backend.pptx
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
ai tools demonstartion for schools and inter college
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Introduction to Artificial Intelligence
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
ISO 45001 Occupational Health and Safety Management System
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Nekopoi APK 2025 free lastest update
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
medical staffing services at VALiNTRY
Transform Your Business with a Software ERP System
L1 - Introduction to python Backend.pptx
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
How to Migrate SBCGlobal Email to Yahoo Easily
ai tools demonstartion for schools and inter college
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Introduction to Artificial Intelligence
How to Choose the Right IT Partner for Your Business in Malaysia
VVF-Customer-Presentation2025-Ver1.9.pptx
ISO 45001 Occupational Health and Safety Management System
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Softaken Excel to vCard Converter Software.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
2025 Textile ERP Trends: SAP, Odoo & Oracle
PTS Company Brochure 2025 (1).pdf.......
Nekopoi APK 2025 free lastest update
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool

Page Fragments как развитие идеи Page Object паттерна

  • 1. Page Fragments OR PAGE ELEMENTS OR HTML ELEMENTS OLEKSANDR KHOTEMSKYI http://xotabu4.github.io EXTENDING IDEAS OF PAGE OBJECTS PATTERN
  • 2. In this presentation 1. Quick explanation of modern Page Objects 2. Idea of Page Fragments 3. What this gives to us? 4. Code examples
  • 5. Idea of page object • Based on OOP principles • One class describes one page • Pages can inherit one from another • Additional layer of abstraction for our tests • Extracts elements manipulations from test logic Page Notes RecycleBin Archive createNote (title, body) {} deleteNote (index) {} archiveNote (index) {} changeNoteColor (index, color) {} editNote (index, title, body) {} deleteNoteForever (index) {} restoreNote (index) {} unarchiveNote (index) {} deleteNote (index) {} changeNoteColor (index, color) {} editNote (index, title, body) {} openRecycleBinPage() openArchivePage() openNotesPage()
  • 6. Idea of page object • Elements are belongs to object instance, usually as class fields or instance attribute • Elements should be initialized in proper time • Methods describe actions that user can do on the page NotesPage headerMenuButton openRecycleBinPageLink openArchivePageLink openNotesPageLink createNoteField deleteNoteButtons archiveNoteButtons changeColorButtons …
  • 7. Best practices • Page object methods should do only what specified in their name • This means not less than needed to make action completed, not more than needed to make action completed • Use inheritance, composition, use reliable locators, chain searching of elements • If you have repeatable complex actions in your tests – use models to reduce copy-paste
  • 9. Modern apps consist of different components
  • 10. Idea of Fragments • Reproduce the same structure of objects on the page that we already have in our application • Now page is not the smallest object in framework • Break fragments into smaller fragments • Group smaller fragments into bigger fragments • Reuse methods of child fragments in parent fragment NoteFragment INCLUDES fragments: ArchiveButton ChangeColorButton DeleteButton getTitle() getBody() edit(title, body) changeColor(color) delete() archive()
  • 11. Fragments • Use chaining for elements search where possible • Search inside element instead searching everywhere on the page • As an option, pass root element into constructor as parameter, and use it to make all searches inside this element let deleteButton = browser.element(by.css('button.delete')) Better: Bad:
  • 12. Idea of Fragments • Inherit one fragment from another • Use power of OOP • Introduce types in languages without strict types (JS, Python) to enable autocomplete in IDE • Use interfaces, abstract classes to introduce parent objects NoteFragment ArchivedNoteFragment DeletedNoteFragment AbstractNoteFragment ??? Fragment
  • 14. Custom collections of own fragments • Create custom collections with your fragments • Works like usual array/list/etc , but extended with your own methods • Iterate thru collection, apply filters • Best works for things like search results • Feature state: • Java – tested and used in prod • Python – not investigated (3rd party libs exists) • JS (ProtractorJS) – testing and bug fixing NotesArrayFragment get(index) -> returns NoteFragment count() map() filter() … hasNoteWithTitle(title) hasNoteWithTitle(body) hasNoteWithColor(title)
  • 15. Inherit from WebElement object • Your fragments now valid WebElements • Your custom fragments can be passed to any methods that require WebElement as parameter • Override existing WebElement methods, such as isDisplayed() for even more flexibility (if needed) WebElement Object Inheritance chain FooFragment BarFragment
  • 16. What this gives to us?
  • 17. Benefits • Nice reusing of components across different pages or even projects • Better stability on locators changes • Logic spited across smaller parts – easier to change • Cleaner code • Easier to understand because everything has it own names • Can be applied to any tool/programming language. Also works for non-web applications
  • 18. Hard parts • Requires good understanding of OOP principles • Requires to write more code • Might be not needed in tiny projects – best works in applications with a lot of similar fragments • Idea is not used widely. Everyone building own approach • Additional framework layer in your code
  • 30. Now it is time to ask questions https://github.com/Xotabu4/protractor-element-extend http://xotabu4.github.io/

Editor's Notes

  • #6: http://www.hiteshbalar.com/preserver/notes
  • #7: Этот подход вообще не ок, и взят только как пример. К сожалению обычно в проектах я вижу именно так.
  • #8: Roma расскажет про модельки первым.