2. +
Myths about POM
POM is creating separate classes for each pages in
application.
Adding all required web elements and methods in that class.
3. +
Messed Up..
People create classes for different pages or functionality
People add all required web elements and methods in that
class.
People do not think in object oriented view beyond creating
classes for different pages or functionalities.
4. +
More Object Oriented..
Observe your application in object oriented way.
Create layers of your application in two parallel streams.
First stream with layers of objects in your applications
Second stream with layers of functionalities performed by each
layer of objects
5. +
How???
First consider first page of your application as one class.
List down different major components in your page class.
List down different functionalities performed by those
components.
6. +
Implementing OOP to Page class:
Now consider each individual major component as single class.
Again apply layered class pattern to these components.
Divide your one component into more granular components.
Now consider each granular component as single class.
7. +
Finally :
So ultimately you will have layers of classes.
Your page class will have objects for major component classes.
Your component classes will have objects for granular
component classes.
Ultimately you will have object oriented mirror image of your
application.
8. +
Example:-
Consider an ecommerce website.
Consider a test case for searching an item and then sorting the
result list.
Now we will create object oriented layered structure.
9. +
Continued..
First of all, we see an application. So consider first class as
your application.
Now we are on home page. Your home page is one component
of your application. Let’s consider your home page as second
class.
10. +
Continued..
Now first test step is to search for one item.
For example I want to buy and iPhone. So I will search for
iPhone. I want cheapest one so I will sort result based on lowest
price first.
11. +
Continued..
To search an item I have to interact with search input box and
search button.
So lets consider this component as our next class.
12. +
Continued..
Now once I search for iPhone then I will receive list of result.
To select an item I have to interact with search result list.
Lets consider this as our next class
13. +
Continued..
Now my search result list may have multiple items from
different vendors.
So my result list is made up of different search result item.
So here is our next class for search result item.
14. +
List of Classes :
Ultimately now we have different classes as
1. Application Class
2. Home Page Class
3. Search Panel Class
4. Search Result List Class
5. Search Result List Item Class
15. +
Layers of Classes :
Now Search Panel class and Search Result List class are at
same layer.
They are direct components of Home Page class.
16. +
Hierarchy /Layered structure :
Application
Home Page
Search
Panel
Search
Result List
Search
Result List
Item
Another
Page
17. +
Layers of Functionality :
In similar way we will create layers of functionality.
Each class will have the functionalities performed by that
component.
We will need to analyze functionality with two points
- Whether that action is performed by object of that class
- Whether object of that class is calling method of lower layer class
to perform that action
18. +
Example:
Ecommerce website have search functionality and sort result
functionality.
When user want to search an item then user opens application
-> Go to Home Page -> Go to Search Panel -> and perform
search action.
In similar way, our application class will have search
functionality which is not actually performed by object of tat
class rather application class object calls search functionality of
home page class.
19. +
Continued :
Home page class will have search functionality. But rather
implementing search functionality in home page class , it
should actually call search functionality of Search panel in its
method.
And finally logic/code for search functionality should be
implemented in search panel class.
20. +
Hierarchy/Layered Structure :
Application Class -
Search
Sort
Login
Home Page-
Search
Sort
Search Panel-
Search
Search Result List-
Sort
Search Result List
Item-
Comparator
implementation
Login Page-
Login