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
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
Now it is time to ask questions
https://github.com/Xotabu4/protractor-element-extend
http://xotabu4.github.io/

More Related Content

What's hot

it's just search
it's just searchit's just search
it's just search
Erik Hatcher
 
Lucene for Solr Developers
Lucene for Solr DevelopersLucene for Solr Developers
Lucene for Solr Developers
Erik Hatcher
 
Examiness hints and tips from the trenches
Examiness hints and tips from the trenchesExaminess hints and tips from the trenches
Examiness hints and tips from the trenches
Ismail Mayat
 
Building your own search engine with Apache Solr
Building your own search engine with Apache SolrBuilding your own search engine with Apache Solr
Building your own search engine with Apache Solr
Biogeeks
 
ElasticSearch, Elastica, ElasticaBundle
ElasticSearch, Elastica, ElasticaBundleElasticSearch, Elastica, ElasticaBundle
ElasticSearch, Elastica, ElasticaBundle
Nicolas Badey
 
06.1 .Net memory management
06.1 .Net memory management06.1 .Net memory management
06.1 .Net memory management
Victor Matyushevskyy
 
02 beginning code first
02   beginning code first02   beginning code first
02 beginning code first
Maxim Shaptala
 
Improving Top-K Retrieval Algorithms Using Dynamic Programming and Longer Ski...
Improving Top-K Retrieval Algorithms Using Dynamic Programming and Longer Ski...Improving Top-K Retrieval Algorithms Using Dynamic Programming and Longer Ski...
Improving Top-K Retrieval Algorithms Using Dynamic Programming and Longer Ski...
Sease
 
Integrating the Solr search engine
Integrating the Solr search engineIntegrating the Solr search engine
Integrating the Solr search engine
th0masr
 
code4lib 2011 preconference: What's New in Solr (since 1.4.1)
code4lib 2011 preconference: What's New in Solr (since 1.4.1)code4lib 2011 preconference: What's New in Solr (since 1.4.1)
code4lib 2011 preconference: What's New in Solr (since 1.4.1)
Erik Hatcher
 
Delving (Smalltalk) Source Code
Delving (Smalltalk) Source CodeDelving (Smalltalk) Source Code
Delving (Smalltalk) Source Code
ESUG
 
Ponies and Unicorns With Scala
Ponies and Unicorns With ScalaPonies and Unicorns With Scala
Ponies and Unicorns With Scala
Tomer Gabel
 
Jena Programming
Jena ProgrammingJena Programming
Jena Programming
Myungjin Lee
 
Python first day
Python first dayPython first day
Python first day
MARISSTELLA2
 
Python first day
Python first dayPython first day
Python first day
farkhand
 
Battle of the giants: Apache Solr vs ElasticSearch
Battle of the giants: Apache Solr vs ElasticSearchBattle of the giants: Apache Solr vs ElasticSearch
Battle of the giants: Apache Solr vs ElasticSearch
Rafał Kuć
 
Elasticsearch and Symfony Integration - Debarko De
Elasticsearch and Symfony Integration - Debarko DeElasticsearch and Symfony Integration - Debarko De
Elasticsearch and Symfony Integration - Debarko De
Debarko De
 
Information Retrieval - Data Science Bootcamp
Information Retrieval - Data Science BootcampInformation Retrieval - Data Science Bootcamp
Information Retrieval - Data Science Bootcamp
Kais Hassan, PhD
 
OCAS @ ISWC 2011 - Generic Multilevel Approach Designing Domain Ontologies Ba...
OCAS @ ISWC 2011 - Generic Multilevel Approach Designing Domain Ontologies Ba...OCAS @ ISWC 2011 - Generic Multilevel Approach Designing Domain Ontologies Ba...
OCAS @ ISWC 2011 - Generic Multilevel Approach Designing Domain Ontologies Ba...
Dr.-Ing. Thomas Hartmann
 
070517 Jena
070517 Jena070517 Jena
070517 Jena
yuhana
 

What's hot (20)

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

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

Java scriptforjavadev part2a
Java scriptforjavadev part2aJava scriptforjavadev part2a
Java scriptforjavadev part2a
Makarand Bhatambarekar
 
Eclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDTEclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDT
deepakazad
 
JS Essence
JS EssenceJS Essence
JS Essence
Uladzimir Piatryka
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojo
Fu Cheng
 
Web scraping using scrapy - zekeLabs
Web scraping using scrapy - zekeLabsWeb scraping using scrapy - zekeLabs
Web scraping using scrapy - zekeLabs
zekeLabs Technologies
 
Apache Calcite (a tutorial given at BOSS '21)
Apache Calcite (a tutorial given at BOSS '21)Apache Calcite (a tutorial given at BOSS '21)
Apache Calcite (a tutorial given at BOSS '21)
Julian Hyde
 
Effiziente persistierung
Effiziente persistierungEffiziente persistierung
Effiziente persistierung
Thorben Janssen
 
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
Effiziente Datenpersistierung mit JPA 2.1 und HibernateEffiziente Datenpersistierung mit JPA 2.1 und Hibernate
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
Thorben Janssen
 
How to train the jdt dragon
How to train the jdt dragonHow to train the jdt dragon
How to train the jdt dragon
Ayushman Jain
 
SQLGitHub - Access GitHub API with SQL-like syntaxes
SQLGitHub - Access GitHub API with SQL-like syntaxesSQLGitHub - Access GitHub API with SQL-like syntaxes
SQLGitHub - Access GitHub API with SQL-like syntaxes
Jasmine Chen
 
Angular JS
Angular JSAngular JS
Angular JS
John Temoty Roca
 
Ajaxworld
AjaxworldAjaxworld
Ajaxworld
deannalagason
 
Session 14 - Object Class
Session 14 - Object ClassSession 14 - Object Class
Session 14 - Object Class
PawanMM
 
oop 3.pptx
oop 3.pptxoop 3.pptx
oop 3.pptx
OsamaMuhammad18
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
Ankur Dongre
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
Ankur Dongre
 
Full Text Search In PostgreSQL
Full Text Search In PostgreSQLFull Text Search In PostgreSQL
Full Text Search In PostgreSQL
Karwin Software Solutions LLC
 
TDD with phpspec2
TDD with phpspec2TDD with phpspec2
TDD with phpspec2
Anton Serdyuk
 
Introduction to Python and Django
Introduction to Python and DjangoIntroduction to Python and Django
Introduction to Python and Django
solutionstreet
 
Object Class
Object Class Object Class
Object Class
Hitesh-Java
 

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

Java scriptforjavadev part2a
Java scriptforjavadev part2aJava scriptforjavadev part2a
Java scriptforjavadev part2a
 
Eclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDTEclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDT
 
JS Essence
JS EssenceJS Essence
JS Essence
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojo
 
Web scraping using scrapy - zekeLabs
Web scraping using scrapy - zekeLabsWeb scraping using scrapy - zekeLabs
Web scraping using scrapy - zekeLabs
 
Apache Calcite (a tutorial given at BOSS '21)
Apache Calcite (a tutorial given at BOSS '21)Apache Calcite (a tutorial given at BOSS '21)
Apache Calcite (a tutorial given at BOSS '21)
 
Effiziente persistierung
Effiziente persistierungEffiziente persistierung
Effiziente persistierung
 
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
Effiziente Datenpersistierung mit JPA 2.1 und HibernateEffiziente Datenpersistierung mit JPA 2.1 und Hibernate
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
 
How to train the jdt dragon
How to train the jdt dragonHow to train the jdt dragon
How to train the jdt dragon
 
SQLGitHub - Access GitHub API with SQL-like syntaxes
SQLGitHub - Access GitHub API with SQL-like syntaxesSQLGitHub - Access GitHub API with SQL-like syntaxes
SQLGitHub - Access GitHub API with SQL-like syntaxes
 
Angular JS
Angular JSAngular JS
Angular JS
 
Ajaxworld
AjaxworldAjaxworld
Ajaxworld
 
Session 14 - Object Class
Session 14 - Object ClassSession 14 - Object Class
Session 14 - Object Class
 
oop 3.pptx
oop 3.pptxoop 3.pptx
oop 3.pptx
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Full Text Search In PostgreSQL
Full Text Search In PostgreSQLFull Text Search In PostgreSQL
Full Text Search In PostgreSQL
 
TDD with phpspec2
TDD with phpspec2TDD with phpspec2
TDD with phpspec2
 
Introduction to Python and Django
Introduction to Python and DjangoIntroduction to Python and Django
Introduction to Python and Django
 
Object Class
Object Class Object Class
Object Class
 

Recently uploaded

14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
ShulagnaSarkar2
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
safelyiotech
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
dakas1
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
kalichargn70th171
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
TaghreedAltamimi
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
YAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring detailsYAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring details
NishanthaBulumulla1
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
fiscal year variant fiscal year variant.
fiscal year variant fiscal year variant.fiscal year variant fiscal year variant.
fiscal year variant fiscal year variant.
AnkitaPandya11
 

Recently uploaded (20)

14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
YAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring detailsYAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring details
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
fiscal year variant fiscal year variant.
fiscal year variant fiscal year variant.fiscal year variant fiscal year variant.
fiscal year variant fiscal year variant.
 

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
  • 4.
  • 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
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30. Now it is time to ask questions https://github.com/Xotabu4/protractor-element-extend http://xotabu4.github.io/

Editor's Notes

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