Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Page objects in test automation

389 views

Published on

Learn why Page Objects are so effective at making your automated functional tests more stable.

Published in: Internet
  • Be the first to comment

  • Be the first to like this

Page objects in test automation

  1. 1. www.ultimateqa.com 11 Nikolay Advolodkin QA Automation Engineer www.ultimateQA.com @Nikolay_A00 A Single Pattern to Drastically Improve Your Test Automation
  2. 2. www.ultimateqa.com I. Getting Started
  3. 3. www.ultimateqa.com II. Why record and replay test automation is not effective
  4. 4. www.ultimateqa.com Section II 44 Record a test Fix Test Attempt to run test Understand Disadvantages How do we fix problems with our tests?
  5. 5. www.ultimateqa.com III. Learning the pitfalls of Keyword Driven test automation
  6. 6. www.ultimateqa.com Section III 66 Introduction to Keyword Driven Testing Understanding disadvantages How do we fix problems with our Keyword tests?
  7. 7. www.ultimateqa.com IV. Page Object Pattern
  8. 8. www.ultimateqa.com Section IV 88 What are page objects Implementing page objects to fix our tests Advantages and disadvantages Write more tests using page objects
  9. 9. www.ultimateqa.com V. Making Page Objects Even Better
  10. 10. www.ultimateqa.com Section V 1010 Learn DRY Learn SRP Learn How To Deal With Complex Web Pages Improve Tests Improve Tests Improve Tests
  11. 11. www.ultimateqa.com What is one problem that most of us face with functional test automation?
  12. 12. www.ultimateqa.com 20 5 4 Poll: How many tests can you run per day that will give the correct result with 95% accuracy? 1212 2 3 2501 - 1000 1001 - 5000 5000+ 101 - 500 51 - 100 0 - 50
  13. 13. www.ultimateqa.com 1313 Flaky tests (6) Lack of knowledge (6) Framework (6) Synchronization (4) Other, one off issues Poll: What is a problem that you have with test automation?
  14. 14. www.ultimateqa.com Why is functional test automation so flaky?
  15. 15. www.ultimateqa.com 15 User Experience Canvas Touch Events Angular JS SVG Drag & Drop AJAX http://www.evolutionoftheweb.com/
  16. 16. www.ultimateqa.com How can Automation Engineers handle such an evolving world?
  17. 17. www.ultimateqa.com “The only thing constant in software development is change.”
  18. 18. www.ultimateqa.com Tools Used 1818 Version Firefox Selenium Builder Visual Studio Selenium Webdriver 40.0 3.1.2 2015 2.53.1 NUnit 3.4.1.0
  19. 19. www.ultimateqa.com Record and Replay: How many tests need to be updated due to a change in AUT? 1919 How many tests need to be changed? Driver Initialization Url Locators User names/password s Synchronization issues Change Agents All All All All All
  20. 20. www.ultimateqa.com 20 Methods Resilient Lemon drops oat cake oat cake sugar plum sweet gingerbread chocolate cake gingerbread. Portfolio Five Reusable Lemon drops oat cake oat cake sugar plum sweet gingerbread chocolate cake gingerbread. Portfolio Four Advantages of using Keyword Driven Approach
  21. 21. www.ultimateqa.com 21 Too much in 1 file Flow changes break all tests Lemon drops oat cake oat cake sugar plum sweet gingerbread chocolate cake gingerbread. Portfolio Five Method for every action Lemon drops oat cake oat cake sugar plum sweet gingerbread chocolate cake gingerbread. Portfolio Four Disadvantages of using Keyword Driven Approach
  22. 22. www.ultimateqa.com 2222 So what can I do then???? Give me the answer already So unstable!! ArghhhhIt’s Brittle bro!
  23. 23. www.ultimateqa.com Page Object Pattern
  24. 24. www.ultimateqa.com 24 Page Object Pattern Object – Page.cs
  25. 25. www.ultimateqa.com 25 Page Object Pattern Use your code to interact with the application page just like you would interact with it manually Page.ClickStartHereButton() Page.GoToVideoTutorials()
  26. 26. www.ultimateqa.com 26 Abstraction Logical Follows Good Design Principles Maintainable Readable Tests Advantages of Page Object Pattern
  27. 27. www.ultimateqa.com 27 DRY – Don’t Repeat Yourself
  28. 28. www.ultimateqa.com “Duplication is the primary enemy of a well-designed system” Martin, Robert
  29. 29. www.ultimateqa.com 29 Increased barrier to entry Requires constant improvement Lemon drops oat cake oat cake sugar plum sweet gingerbread chocolate cake gingerbread. Portfolio Five Many different options Lemon drops oat cake oat cake sugar plum sweet gingerbread chocolate cake gingerbread. Portfolio Four Disadvantages of using Page Objects
  30. 30. www.ultimateqa.com Creating Improved Page Objects 3030 Cement Understanding of Page Objects Improve the code Tackle solutions to common challenges
  31. 31. www.ultimateqa.com Make Current Page Objects More DRY 1
  32. 32. www.ultimateqa.com Make Current Page Objects Follow SRP 2
  33. 33. www.ultimateqa.com Using complex pages to write simple Page Objects 3
  34. 34. www.ultimateqa.com Recommended Pre-requisites 3434 Strong understanding of Selenium Webdriver API https://goo.gl/71SOfX Good understanding of Object Oriented Programming principles https://goo.gl/YzQ1x4
  35. 35. www.ultimateqa.com A class should have only one reason to change SRP – SingleResponsibility Principle
  36. 36. www.ultimateqa.com Benefits 3636 A change in an unrelated functionality will not break 2 functionalities Changing pizza baking functionality is not going to break how the store delivers the pizza
  37. 37. www.ultimateqa.com How to create simple Page Objects from complex web pages? 3
  38. 38. www.ultimateqa.com 38 Small in code size Easier to read tests Lemon drops oat cake oat cake sugar plum sweet gingerbread chocolate cake gingerbread. Portfolio Five Easier to manage Lemon drops oat cake oat cake sugar plum sweet gingerbread chocolate cake gingerbread. Portfolio Four Advantages of Simple Page Objects
  39. 39. www.ultimateqa.com Required Resources 3939 http://www.ultimateqa.com/automation/ http://www.ultimateqa.com/complicated-page/
  40. 40. www.ultimateqa.com Conclusions 4040 Automation Success Write your code to prepare for inevitable change GUI Automation is hard A fantastic step towards test stability Start using Page Objects Duplication is the enemy Remove duplication Classes should do one thing only Follow Single Responsibility Principle Tests are more readable Classes are smaller Separate large page objects Start Here
  41. 41. www.ultimateqa.com Resources 4141 • Code and Slide Deck - http://wp.me/P7absY-8j • Martin, Robert C.. Clean Code: A Handbook of Agile Software Craftsmanship (Kindle Locations 4076-4077). Pearson Education. Kindle Edition. • Selenium Wiki on Page Objects • Martin Fowler on Page Objects • Dave Haeffner on Page Objects
  42. 42. www.ultimateqa.com Help! Your stupid code doesn’t work Nikolay!
  43. 43. www.ultimateqa.com 43 Step 1: Debug Your Code Remove code and start again Ctrl + Y Ctrl + Z Restart OpenQA.Selenium.WebDriverException: Cannot find Firefox binary in PATH or default install locations. Make sure Firefox is installed. OS appears to be: Vista Read Error Message in IDE Pull my code into your IDE and use a Diff tool. Use Notepad++ Compare plugin Compare to my Code
  44. 44. www.ultimateqa.com 44 Step 2: Check My Blog Selenium errors Search Blog http://www.ultimateqa.com/common- selenium-webdriver-errors-fix/ Go Here
  45. 45. www.ultimateqa.com 45 Step 3: Find Solutions Online Error message + programming language Google
  46. 46. www.ultimateqa.com 46 Step 4: Ask Good Questions No need to be upset It’s a common problem Be Positive http://www.ultimateqa.com/common- selenium-webdriver-errors-fix/ Go Here If you want help, make it easy for the person to help you Concise, Specific Be thankful that someone took time to answer your question Give Thanks

×