SlideShare ist ein Scribd-Unternehmen logo
1 von 30
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/

Weitere ähnliche Inhalte

Was ist angesagt?

Lucene for Solr Developers
Lucene for Solr DevelopersLucene for Solr Developers
Lucene for Solr DevelopersErik 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 trenchesIsmail 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 SolrBiogeeks
 
ElasticSearch, Elastica, ElasticaBundle
ElasticSearch, Elastica, ElasticaBundleElasticSearch, Elastica, ElasticaBundle
ElasticSearch, Elastica, ElasticaBundleNicolas Badey
 
02 beginning code first
02   beginning code first02   beginning code first
02 beginning code firstMaxim 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 engineth0masr
 
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 CodeESUG
 
Ponies and Unicorns With Scala
Ponies and Unicorns With ScalaPonies and Unicorns With Scala
Ponies and Unicorns With ScalaTomer Gabel
 
Python first day
Python first dayPython first day
Python first dayfarkhand
 
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 ElasticSearchRafał Kuć
 
Elasticsearch and Symfony Integration - Debarko De
Elasticsearch and Symfony Integration - Debarko DeElasticsearch and Symfony Integration - Debarko De
Elasticsearch and Symfony Integration - Debarko DeDebarko De
 
Information Retrieval - Data Science Bootcamp
Information Retrieval - Data Science BootcampInformation Retrieval - Data Science Bootcamp
Information Retrieval - Data Science BootcampKais 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 Jenayuhana
 

Was ist angesagt? (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
 

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

Eclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDTEclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDTdeepakazad
 
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 dojoFu Cheng
 
Web scraping using scrapy - zekeLabs
Web scraping using scrapy - zekeLabsWeb scraping using scrapy - zekeLabs
Web scraping using scrapy - zekeLabszekeLabs 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 persistierungThorben 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 HibernateThorben Janssen
 
How to train the jdt dragon
How to train the jdt dragonHow to train the jdt dragon
How to train the jdt dragonAyushman 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 syntaxesJasmine Chen
 
Session 14 - Object Class
Session 14 - Object ClassSession 14 - Object Class
Session 14 - Object ClassPawanMM
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
 
Introduction to Python and Django
Introduction to Python and DjangoIntroduction to Python and Django
Introduction to Python and Djangosolutionstreet
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 

Kürzlich hochgeladen (20)

Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 

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/

Hinweis der Redaktion

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