SlideShare a Scribd company logo
1 of 14
CONFIDENTIAL Copyright © 2008 Constant Contact, Inc. 1 Using Page Objects in Selenium Eric Getchell Quality Engineering Manager Donna Reardon Principal Quality Engineer
CONFIDENTIAL Copyright © 2009 Constant Contact, Inc. 2 Record and Playback  What are Utility Classes and how are they used in testing? What is a Page Object? Some Advantages of Page Objects Re-usability 	Maintainability 	Productivity Gains How to create a Page Object Demo Q & A
Record and Playback – Early Automation Approach ,[object Object]
 Does NOT scale for 1k’s of tests, or even 100’s.
 Not easy to re-use a scenario as part of a larger user  story.
 Requires a large amount of copy/paste to develop each test scenario.Perform a query for “Smith” in the last name field. 	Perform a query for “Smith in the last name field, and  “John” in the first 	name field. CONFIDENTIAL Copyright © 2009 Constant Contact, Inc. 3
Utility Classes Utility classes typically contain methods that are used often in your testing.  It might contain methods for writing to a log file, writing to an event log, or parsing a data file.  Methods can easily be duplicated across classes and hard to find inside large util classes. com.roving.taf.utility.NowString() com.roving.taf.utility.getCurrencyString(numberToConvertToString) CONFIDENTIAL Copyright © 2009 Constant Contact, Inc. 4
What is a Page Object? Page Objects are a representation of a web page.  All elements seen on the web page can be interacted using their respective methods in the page object. Page Objects are classes that allow you to abstract the functionality from the GUI, removing the need for your tests to expose UI components. PageObject: app.addUser() BrowserObject: Window(“App”).button(“Add”).click()  Application logic is then scripted in classes specific to your test scenarios. PageObjects + Test Code = scripted business logic CONFIDENTIAL Copyright © 2009 Constant Contact, Inc. 5
What is a Page Object? ,[object Object]
Exposes methods for actions in the UI, such as
UserRegistration.getFullname();
UserRegistration.setLastname();
Consolidates code specific to UI elements
getFullname() is found on User Registration page, not TemplatePicker page.

More Related Content

What's hot

Overview of MVC Framework - by software outsourcing company india
Overview of MVC Framework - by software outsourcing company indiaOverview of MVC Framework - by software outsourcing company india
Overview of MVC Framework - by software outsourcing company indiaJignesh Aakoliya
 
Automation Testing with KATALON Cucumber BDD
Automation Testing with KATALON Cucumber BDDAutomation Testing with KATALON Cucumber BDD
Automation Testing with KATALON Cucumber BDDRapidValue
 
Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4Rich Helton
 
Hibernate training
Hibernate trainingHibernate training
Hibernate trainingTechFerry
 
Rc085 010d-vaadin7
Rc085 010d-vaadin7Rc085 010d-vaadin7
Rc085 010d-vaadin7Cosmina Ivan
 
ASP.Net MVC 4 [Part - 2]
ASP.Net MVC 4 [Part - 2]ASP.Net MVC 4 [Part - 2]
ASP.Net MVC 4 [Part - 2]Mohamed Abdeen
 
Metamorphosis from Forms to Java: A technical lead's perspective, part II
Metamorphosis from Forms to Java:  A technical lead's perspective, part IIMetamorphosis from Forms to Java:  A technical lead's perspective, part II
Metamorphosis from Forms to Java: A technical lead's perspective, part IIMichael Fons
 
Flavours - Classic/Technical BDD
Flavours - Classic/Technical BDDFlavours - Classic/Technical BDD
Flavours - Classic/Technical BDDDavid Harrison
 
1 aleksandr gritsevski - attd example using
1   aleksandr gritsevski - attd example using1   aleksandr gritsevski - attd example using
1 aleksandr gritsevski - attd example usingIevgenii Katsan
 
Dependency injection in Java, from naive to functional
Dependency injection in Java, from naive to functionalDependency injection in Java, from naive to functional
Dependency injection in Java, from naive to functionalMarian Wamsiedel
 
Less09 2 e_testermodule_8
Less09 2 e_testermodule_8Less09 2 e_testermodule_8
Less09 2 e_testermodule_8Suresh Mishra
 
Eclipse e4 Overview
Eclipse e4 OverviewEclipse e4 Overview
Eclipse e4 OverviewLars Vogel
 
How to easily design and automate test cases.pdf
How to easily design and automate test cases.pdfHow to easily design and automate test cases.pdf
How to easily design and automate test cases.pdfMaveryx
 

What's hot (20)

Overview of MVC Framework - by software outsourcing company india
Overview of MVC Framework - by software outsourcing company indiaOverview of MVC Framework - by software outsourcing company india
Overview of MVC Framework - by software outsourcing company india
 
Xam expertday
Xam expertdayXam expertday
Xam expertday
 
Automation Testing with KATALON Cucumber BDD
Automation Testing with KATALON Cucumber BDDAutomation Testing with KATALON Cucumber BDD
Automation Testing with KATALON Cucumber BDD
 
Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4Overview of CSharp MVC3 and EF4
Overview of CSharp MVC3 and EF4
 
Hibernate training
Hibernate trainingHibernate training
Hibernate training
 
ASP.MVC Training
ASP.MVC TrainingASP.MVC Training
ASP.MVC Training
 
Frontend training
Frontend trainingFrontend training
Frontend training
 
Rc085 010d-vaadin7
Rc085 010d-vaadin7Rc085 010d-vaadin7
Rc085 010d-vaadin7
 
MVC by asp.net development company in india
MVC by asp.net development company in indiaMVC by asp.net development company in india
MVC by asp.net development company in india
 
ASP.Net MVC 4 [Part - 2]
ASP.Net MVC 4 [Part - 2]ASP.Net MVC 4 [Part - 2]
ASP.Net MVC 4 [Part - 2]
 
Metamorphosis from Forms to Java: A technical lead's perspective, part II
Metamorphosis from Forms to Java:  A technical lead's perspective, part IIMetamorphosis from Forms to Java:  A technical lead's perspective, part II
Metamorphosis from Forms to Java: A technical lead's perspective, part II
 
Flavours - Classic/Technical BDD
Flavours - Classic/Technical BDDFlavours - Classic/Technical BDD
Flavours - Classic/Technical BDD
 
QTP Functions
QTP FunctionsQTP Functions
QTP Functions
 
1 aleksandr gritsevski - attd example using
1   aleksandr gritsevski - attd example using1   aleksandr gritsevski - attd example using
1 aleksandr gritsevski - attd example using
 
Dependency injection in Java, from naive to functional
Dependency injection in Java, from naive to functionalDependency injection in Java, from naive to functional
Dependency injection in Java, from naive to functional
 
Less09 2 e_testermodule_8
Less09 2 e_testermodule_8Less09 2 e_testermodule_8
Less09 2 e_testermodule_8
 
Eclipse e4 Overview
Eclipse e4 OverviewEclipse e4 Overview
Eclipse e4 Overview
 
Robotium - sampath
Robotium - sampathRobotium - sampath
Robotium - sampath
 
How to easily design and automate test cases.pdf
How to easily design and automate test cases.pdfHow to easily design and automate test cases.pdf
How to easily design and automate test cases.pdf
 
Bdd Show and Tell
Bdd Show and TellBdd Show and Tell
Bdd Show and Tell
 

Similar to Using Page Objects

Test Automation Framework Development Introduction
Test Automation Framework Development IntroductionTest Automation Framework Development Introduction
Test Automation Framework Development IntroductionGanuka Yashantha
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullySpringPeople
 
Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium  Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium Zoe Gilbert
 
Breaking free from static abuse in test automation frameworks and using Sprin...
Breaking free from static abuse in test automation frameworks and using Sprin...Breaking free from static abuse in test automation frameworks and using Sprin...
Breaking free from static abuse in test automation frameworks and using Sprin...Abhijeet Vaikar
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power pointjustmeanscsr
 
Functional Testing Swing Applications with Frankenstein
Functional Testing Swing Applications with FrankensteinFunctional Testing Swing Applications with Frankenstein
Functional Testing Swing Applications with Frankensteinvivek_prahlad
 
Testing Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation FrameworksTesting Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation FrameworksŁukasz Morawski
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to javaciklum_ods
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptdavejohnson
 
Selenium Testing Training in Bangalore
Selenium Testing Training in BangaloreSelenium Testing Training in Bangalore
Selenium Testing Training in Bangalorerajkamal560066
 
Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)Kevin Schultz
 
Testing for fun in production Into The Box 2018
Testing for fun in production Into The Box 2018Testing for fun in production Into The Box 2018
Testing for fun in production Into The Box 2018Ortus Solutions, Corp
 
Automation testing
Automation testingAutomation testing
Automation testingTomy Rhymond
 
Final Automation Testing
Final Automation TestingFinal Automation Testing
Final Automation Testingpriya_trivedi
 
XML2Selenium Technical Presentation
XML2Selenium Technical PresentationXML2Selenium Technical Presentation
XML2Selenium Technical Presentationjazzteam
 

Similar to Using Page Objects (20)

Test Automation Framework Development Introduction
Test Automation Framework Development IntroductionTest Automation Framework Development Introduction
Test Automation Framework Development Introduction
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium Successfully
 
Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium  Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium
 
Breaking free from static abuse in test automation frameworks and using Sprin...
Breaking free from static abuse in test automation frameworks and using Sprin...Breaking free from static abuse in test automation frameworks and using Sprin...
Breaking free from static abuse in test automation frameworks and using Sprin...
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Functional Testing Swing Applications with Frankenstein
Functional Testing Swing Applications with FrankensteinFunctional Testing Swing Applications with Frankenstein
Functional Testing Swing Applications with Frankenstein
 
Testing Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation FrameworksTesting Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation Frameworks
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
 
Selenium Testing Training in Bangalore
Selenium Testing Training in BangaloreSelenium Testing Training in Bangalore
Selenium Testing Training in Bangalore
 
Test Automation
Test Automation Test Automation
Test Automation
 
About QTP 9.2
About QTP 9.2About QTP 9.2
About QTP 9.2
 
About Qtp_1 92
About Qtp_1 92About Qtp_1 92
About Qtp_1 92
 
About Qtp 92
About Qtp 92About Qtp 92
About Qtp 92
 
Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)Building Maintainable Android Apps (DroidCon NYC 2014)
Building Maintainable Android Apps (DroidCon NYC 2014)
 
Testing for fun in production Into The Box 2018
Testing for fun in production Into The Box 2018Testing for fun in production Into The Box 2018
Testing for fun in production Into The Box 2018
 
Automation testing
Automation testingAutomation testing
Automation testing
 
Final Automation Testing
Final Automation TestingFinal Automation Testing
Final Automation Testing
 
XML2Selenium Technical Presentation
XML2Selenium Technical PresentationXML2Selenium Technical Presentation
XML2Selenium Technical Presentation
 
Selenium
SeleniumSelenium
Selenium
 

Using Page Objects

  • 1. CONFIDENTIAL Copyright © 2008 Constant Contact, Inc. 1 Using Page Objects in Selenium Eric Getchell Quality Engineering Manager Donna Reardon Principal Quality Engineer
  • 2. CONFIDENTIAL Copyright © 2009 Constant Contact, Inc. 2 Record and Playback What are Utility Classes and how are they used in testing? What is a Page Object? Some Advantages of Page Objects Re-usability Maintainability Productivity Gains How to create a Page Object Demo Q & A
  • 3.
  • 4. Does NOT scale for 1k’s of tests, or even 100’s.
  • 5. Not easy to re-use a scenario as part of a larger user story.
  • 6. Requires a large amount of copy/paste to develop each test scenario.Perform a query for “Smith” in the last name field. Perform a query for “Smith in the last name field, and “John” in the first name field. CONFIDENTIAL Copyright © 2009 Constant Contact, Inc. 3
  • 7. Utility Classes Utility classes typically contain methods that are used often in your testing. It might contain methods for writing to a log file, writing to an event log, or parsing a data file. Methods can easily be duplicated across classes and hard to find inside large util classes. com.roving.taf.utility.NowString() com.roving.taf.utility.getCurrencyString(numberToConvertToString) CONFIDENTIAL Copyright © 2009 Constant Contact, Inc. 4
  • 8. What is a Page Object? Page Objects are a representation of a web page. All elements seen on the web page can be interacted using their respective methods in the page object. Page Objects are classes that allow you to abstract the functionality from the GUI, removing the need for your tests to expose UI components. PageObject: app.addUser() BrowserObject: Window(“App”).button(“Add”).click() Application logic is then scripted in classes specific to your test scenarios. PageObjects + Test Code = scripted business logic CONFIDENTIAL Copyright © 2009 Constant Contact, Inc. 5
  • 9.
  • 10. Exposes methods for actions in the UI, such as
  • 13. Consolidates code specific to UI elements
  • 14. getFullname() is found on User Registration page, not TemplatePicker page.
  • 15. Not tied to a specific framework
  • 16. Can be used in Selenium, Webdriver, QTP, etc.CONFIDENTIAL Copyright © 2009 Constant Contact, Inc. 6
  • 17.
  • 18. Allows for other -ilities, maintainability, re-useability, etc. public static final String TEXT_loginName = "username"; public static final String TEXT_loginPassword = "password"; CONFIDENTIAL Copyright © 2009 Constant Contact, Inc. 7
  • 19.
  • 20. Constants can be used and overloaded, depending on the data requirements or test case behavior.
  • 21. Hashmaps can be used as constants to prepopulate methods – and subsequently overloaded to replace values for different test scenariosselectColor(String color) public static booleanselectColorBlue() throws Exception { return selectColor("blue"); } CONFIDENTIAL Copyright © 2009 Constant Contact, Inc. 8
  • 22.
  • 23. This allows for testers to quickly update their test scenarios.
  • 24. The alternative would be to find all test scenarios that use the login() and update them individually.
  • 25. Makes tests less brittle by writing tests with code that allows for exception catching/conditionalizingCONFIDENTIAL Copyright © 2009 Constant Contact, Inc. 9
  • 26.
  • 27. Test development is more simplistic and can be data driven
  • 28. Reusability of multiple Page Objects allow for user flows to be scripted more quickly
  • 29. Test code is more readableCONFIDENTIAL Copyright © 2009 Constant Contact, Inc. 10
  • 30. The Advantages of Page Objects Example Productivity Increases through Re-Use and Maintainability ** LoginViaAPI has 454 References In Test Cases ** com.roving.taf.pages.UI.loginViaAPI(PARAM_username, PARAM_password); public static void loginViaAPI(String userName, String password, booleanonFailLogCritical) throws Exception { Rpt.info("UI Login via API Being Attempted - " + userName + " / " + password); com.roving.taf.pages.api.APIs.apiLogin(userName, password); isUserLoggedIn(onFailLogCritical); } CONFIDENTIAL Copyright © 2009 Constant Contact, Inc. 11
  • 31. Page Objects In Use – How to create a Page Object Start by … Run Firebug (Firefox plugin) to inspect elements Create a class in a package that has a logical name (lp.login). Declare a variable with the definition obtained from Firebug Have a defined naming convention Add methods to interact with newly defined objects. Consider exception handling for all methods Consider constants for data that does not change frequently Consider constants for expected error messages Consider standardized methods for commonly used actions, such as “goToPage” Consider collaboration with Development for object ID’s (for example all elements need to have an ID) Overloading methods for variability in testing Consider using the Page Title as a variable/constant to be used for page validation As a rule, do not put assertions in page classes (they belong in the test code) Create test code to reference page object methods Reference the objects through methods For additional information please visit… http://code.google.com/p/selenium/wiki/PageFactory CONFIDENTIAL Copyright © 2009 Constant Contact, Inc. 12
  • 32. Appendix slides… CONFIDENTIAL Copyright © 2009 Constant Contact, Inc. 13
  • 33. Hashmap constant used in a method /* This Hashtable contains all of the calculations on the billing selections page. */ public static Hashtable<String, Double> calcPrepayProdPrice(String em,Stringsurvey,Stringevm,Stringih,Stringarchive,intprepayTerm,StringdiscountPct,doubletaxRate) throws Exception{ Hashtable<String, Double> prodPrice = new Hashtable<String, Double>(); prodPrice.put("em", new Double(emDouble)); prodPrice.put("evm", new Double(evmDouble)); prodPrice.put("survey",new Double(surveyDouble)); prodPrice.put("ih",new Double(ihDouble)); prodPrice.put("archive",new Double(archiveDouble)); prodPrice.put("total", new Double (prodPrice.get("em")+prodPrice.get("evm")+prodPrice.get("survey")+prodPrice.get("ih")+prodPrice.get("archive"))); prodPrice.put("prepayDiscount",new Double(calculatePrepayDiscountVerifySel(prodPrice.get("total"),discountPct))); prodPrice.put("subtotal",new Double(calculateSubTotal(prodPrice.get("total"),discountPct))); BigDecimal Subtotal = new BigDecimal(prodPrice.get("subtotal")); BigDecimalPrepayterm = new BigDecimal(prepayTerm); BigDecimal Tax = new BigDecimal(taxRate); BigDecimal value; /* * Tax is calculated as such: * SubTotal / PrePayTerm = x 189 / 6 = 31.5 * x * taxRate = y rounded up 31.5 * .0625 = 1.96875 rounded up to 1.97 * y * PrePayTerm = Total Tax 1.97 * 6 = 11.82 -> Total Tax */ prodPrice.put("salesTax",new Double (value.doubleValue())); prodPrice.put("totalPlusTax",new Double(prodPrice.get("subtotal") + prodPrice.get("salesTax"))); prodPrice.put("avgMonthlyCost",prodPrice.get("totalPlusTax")/prepayTerm); prodPrice.get("salesTax"); return prodPrice; } CONFIDENTIAL Copyright © 2009 Constant Contact, Inc. 14

Editor's Notes

  1. Talk towards inefficientutil classes due to large size (100’s of methods). Talk towards same/similar methods across multiple methods.
  2. Have 3 references for login, API, UI and LPs. Not all tests were required to log in via UI, so we only needed to change one method in order to log in (API). Also, removed the complexity and risk of having to test through ALL applications – just go straight to API’s for test setups.