Page Object Model
Why Page Object Model?
• Building a test framework
• Easily maintain and update page elements
• Create simple, clean tests
• Simplify the purpose for each class
So far, we have written
our tests in one class file.
Challenges with Tests:
• Not very readable
• Not easy to update page elements
• Not easy to modify test steps
• What if we wanted to run a test
involving many of the same steps?
Framework
Booking Reservation
tests
utilities
DriverFactory Screenshot Logging CSV Excel Database WriteResults
Page Object Model Framework
ShoppingCart
CheckCart
Home Page
Product Search Home Page
Add to Cart User Login
Modify Cart View Cart
Checkout Modify Cart
Confirmation
Page Object Model Framework
ShoppingCart
CheckCart
Home Page
Product Search Home Page
Add to Cart User Login
Modify Cart View Cart
Checkout Modify Cart
Confirmation
POM Solution: Split into Two Classes
One for the test steps, one for the page elements
pages/LoginPage
LoginTest Encapsulate page elements
and web actions with methods
tests/LoginTest
Create instance of the page
object and call action methods
Page Object Model Framework
ShoppingCart CheckCart
tests
pages
Home Login ViewCart Checkout
Search AddCart Modify Confirmation
Page Object Model Framework
ShoppingCart CheckCart
tests
pages
Home Login ViewCart Checkout
Search AddCart Modify Confirmation
Enhance POM with PageFactory
pages/LoginPage.java
Use the constructor method to
LoginTest.java initialize Web Elements using
the PageFactory.init method
tests/LoginTest.java