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.

DSL, Page Object and Selenium – a way to reliable functional tests


Published on

Presentation from first Selenium conference in Europe - Selenium Camp ( about different test design approaches to make functional tests on Selenium more flexible, reliable and stable.

Published in: Technology

DSL, Page Object and Selenium – a way to reliable functional tests

  1. 1. DSL, Page Object and Selenium – a way to reliable functional tests <br />Mikalai Alimenkou<br /><br />26.02.2011<br />
  2. 2. Background<br />Java Technical Lead/Scrum Master at Zoral Labs<br />6+ years in software development<br />4+ years of working by Agile methodologies<br />Expert in Agile engineering practices<br />Agile coach (TDD, Testing, Planning, etc.)at XP Injection (<br />
  3. 3. Agenda<br />Selenium tests issues<br />Step 1: DSL introduction<br />Step 2: Page Object pattern<br />Step 3: Page Element pattern<br />Results analysis<br />
  4. 4. Selenium TESTS Issues<br />When you have a hammer, everything looks like a nail<br />
  5. 5. Test Components<br />Application Driver<br />Test Data<br />Test<br />Logic<br />
  6. 6. How Selenium Works?<br />Get Browser<br />InvokeCommands<br />Provide Data<br />Use Locators<br />
  7. 7. Selenium Tests Issues: Verbose<br />xpath=//input[@value=‘continue’]<br />browser.enter…<br />…<br />css=#results dip p.first<br />browser.getXpathCount…<br />id=greenButton<br />browser.waitForPageToLoad…<br />browser.check…<br />
  8. 8. Selenium Tests Issues: Not Expressive<br />
  9. 9. Selenium Tests Issues: Unreadable<br />
  10. 10. Selenium Tests Issues: Fragile<br />"//input[@id=(//label[text()='Fax']/@for)] ");<br />What is going on here?<br />browser.getText(“//div[@id='App']/div/p[4]/div[1]/h4[@class='Online']”);<br />Depends too much on page structure!<br />
  11. 11. Even More Hidden Issues<br />
  12. 12. What is the Primary Goal?<br />To enable reliable stable tests we need to separate all parts as much as possible<br />
  13. 13. Ideal Testing Framework<br />Test Data Storage<br />Technical Data Storage<br />
  14. 14. Step 1: Introduce DSL<br />Create domain-specific language for your application<br />
  15. 15. Definition of DSL<br />A domain-specific language (DSL) is a programming language or specification language dedicated to a particular problem domain, that is created specifically to solveproblems in this particular domain and is not intended to be able to solve problems outside it (although that may be technically possible).<br />
  16. 16. DSL Usage Sample<br />
  17. 17. DEMO<br />
  18. 18. Benefits of DSL Approach<br />High-level – tests are in the language of product management, at the user level<br />Readable – product management can understand them<br />Writable – easy for developer or QA to write new test<br />Extensible – tests base is able to grow with DSL<br />
  19. 19. Tips and Tricks<br />Use test class hierarchy or test helpers<br />Use builders, visitors and other design patterns<br />Reuse domain model from application<br />Some common methods move to base test class<br />Minimize usage of browser instance in tests<br />
  20. 20. Step 2: Introduce Page Object<br />Create page map for your application<br />
  21. 21. Page Object Pattern<br />Index Page<br />order<br />search<br />Search Page<br />login<br />search<br />filter<br />Main Page<br />open<br />see more<br />Details Page<br />close<br />show me like this<br />
  22. 22. Test Architecture with Page Object<br />
  23. 23. Components Architecture<br />Isolated<br />logic<br />Concepts<br />separation<br />Easier support<br />Simplicity<br />
  24. 24. Ways to Implement Page Object<br />Duplicate Site Map<br />with Packages and <br />Classes<br />Move Site Structure <br />to UI-Element<br />
  25. 25. DEMO<br />
  26. 26. Tips and Tricks<br />Allow chain invocations<br />Basic page with browser details and common methods<br />Expose only what is allowed to see or do on the page<br />Don’t use browser instance in tests at all<br />Use static analysis to check rules<br />Use site map to prepare Page Objects<br />
  27. 27. Step 3: Page Elements<br />Divide pages on reusable elements <br />
  28. 28. Page Consists of Elements<br />Menu<br />Checkbox<br />Panel<br />Link<br />List of Items<br />
  29. 29. Different Page Elements<br />
  30. 30. Why Page Element Pattern?<br />
  31. 31. Inversion of Control<br />Hides the details of browser communication<br />After<br />Before<br />Expose methods for what test can see and do<br />
  32. 32. DEMO<br />
  33. 33. Tellurium Project<br />
  34. 34. Tellurium Basics: UI Module<br />Groovy File<br />Can Build Xpath in Runtime<br />All Elements<br />Element UID<br />Isolated Locators<br />Available Actions<br />
  35. 35. Tellurium Basics: UI Object<br />uid– unique in UI module <br />namespace – for future extension<br />locator – locator of the UI object<br />A base locator (relative XPath)<br />A composite locator (object attributes)<br />group – applied to some kinds of UI objects to switch on grouping locating<br />respond – define JavaScript events the UI object could respond to<br />some basic methods – isElementPresent, isVisible, isDisabled, waitForElementPresent, getText, mouseOver, mouseOut, getAttribute<br />
  36. 36. Tellurium IDE and TrUMP<br />
  37. 37. DEMO<br />
  38. 38. Tips and Tricks<br />Create elements when first need them<br />Review and improve elements continuously<br />Isolate and hide hacks inside elements<br />Use open source libraries as basis<br />Use annotations and other metadata techniques to simplify creation<br />
  39. 39. Results ANALYSIS<br />What we have at the end of long way?<br />
  40. 40. Long Way Bring Us to…<br />Reliable tests<br />Reusable test code<br />Separation of concepts <br />Expressive tested UI structure<br />Short and clear tests<br />Tests look more like acceptance tests<br />Tests are understood by non-technical people<br />
  41. 41. Company DSL Library<br />Components may be reused between different applications and projects inside a company<br />AJAX Components<br />Company Portal<br />Basic Components<br />Online Store<br />JSF<br />Components<br />Customer Service<br />
  42. 42. Any Questions?<br />