Your SlideShare is downloading. ×
DSL, Page Object и WebDriver – путь к надежным функциональным тестам
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

DSL, Page Object и WebDriver – путь к надежным функциональным тестам


Published on

Николай Алименков - доклад на SQA Days, 2-3 декабря 2011, Москва

Николай Алименков - доклад на SQA Days, 2-3 декабря 2011, Москва

Published in: Education, Technology

1 Comment
1 Like
No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. DSL, Page Object and WebDriver –the path to reliable functional tests Mikalai Alimenkou 06.10.2011
  • 2. Background• Java Technical Lead/Scrum Master at Zoral Labs• 7+ years in software development• 5+ years of working by Agile methodologies• Expert in Agile engineering practices• Agile coach (TDD, Testing, Planning, etc.) at XP Injection (• Organizer of Selenium Camp, JEEConf and XP Days Ukraine conferences
  • 3. Agenda• WebDriver tests issues• Step 1: DSL introduction• Step 2: Page Object pattern• Step 3: Page Element pattern• Results analysis
  • 4. When you have a hammer, everything looks like a nailWEBDRIVER TESTS ISSUES
  • 5. Test ComponentsApplication Test Driver Data Test Logic
  • 6. How WebDriver Works? Get Driver Invoke Commands Provide Data Use Locators
  • 7. Selenium Tests Issues: Verbose By.xpath(“//input*@value=‘continue’+”) driver.findElement(By.xpath(…)).sendKeys(…);driver.findElement(…)).click(); By.css(“#results dip p.first”)“greenButton”) driver.findElements(…).size(); new WebDriverWait(driver, 30).until(…);
  • 8. Selenium Tests Issues: Not Expressive
  • 9. Selenium Tests Issues: Unreadable
  • 10. Selenium Tests Issues: Fragiledriver.findElement(By.xpath("//input[@id=(//label[text()=Fax]/@for)]")).click(); What is going on here?driver.findElement(By.xpath("//div[@id=App]/div/p[4]/div[1]/h4[@class=Online]")).getText() Depends too much on page structure!
  • 11. Even More Hidden Issues Test code duplication Hard to understand No reuseFewer tests Hard to created support Hard to Test wrong create new things Performance problems
  • 12. What is the Primary Goal? To enable reliable stable tests we need to separate all parts as much as possible Reliability ClarityTest TestData Logic Flexibility Application Maintainability Driver Stability
  • 13. Ideal Testing Framework Test Logic Test Data Storage DSL Application Driver Technical Driver Technical Data StorageApplication Under Testing
  • 14. Create domain-specific language for your applicationSTEP 1: INTRODUCE DSL
  • 15. Definition of DSL A domain-specific language (DSL) is a programming language or specificationlanguage dedicated to a particular problemdomain, that is created specifically to solve problems in this particular domain and is not intended to be able to solve problemsoutside it (although that may be technically possible).
  • 16. DSL Usage Sample
  • 17. DEMO
  • 18. Benefits of DSL Approach• High-level – tests are in the language of product management, at the user level• Readable – product management can understand them• Writable – easy for developer or QA to write new test• Extensible – tests base is able to grow with DSL
  • 19. Tips and Tricks• Use test class hierarchy or test helpers• Use builders, visitors and other design patterns• Reuse domain model from application• Some common methods move to base test class• Minimize usage of driver instance in tests
  • 20. Create page map for your applicationSTEP 2: INTRODUCE PAGE OBJECT
  • 21. Page Object Pattern search orderIndex Page Search Pagelogin search filterMainPage open see more Details close Page show me like this
  • 22. Test Architecture with Page Object
  • 23. Components ArchitectureIsolated Concepts logic separation Easier support Simplicity
  • 24. Ways to Implement Page Object Duplicate Site Map with Packages and ClassesMove Site Structure to UI-Element
  • 25. WebDriver Page Object Support
  • 26. DEMO
  • 27. “Ideal” Page Object in WebDriver
  • 28. Tips and Tricks• Allow chain invocations• Basic page with driver details and common methods• Use already included Page Object classes to simplify pages creation• Expose only what is allowed to see or do on the page• Don’t use driver instance in tests at all• Use static analysis to check rules• Use site map to prepare Page Objects
  • 29. Divide pages on reusable elementsSTEP 3: PAGE ELEMENTS
  • 30. Page Consists of Elements Menu Checkbox PanelLinkList of Items
  • 31. Different Page Elements Checkbox TextBox Button• click • type • click• isChecked • hasValue • doubleClick• check • focus • clickAndWait• uncheck • clearText • …• … • typeAndReturn • isEditable • …Table Items Menu Panel Form
  • 32. Why Page Element Pattern? Highest Clear page level of structure code reuse Building Reliable pages from tests components
  • 33. Inversion of ControlHides the details ofbrowser communication After Before Expose methods for what test can see and do
  • 34. DEMO
  • 35. Tellurium Project
  • 36. Tellurium Basics: UI Module Groovy File Can Build XPath in Runtime AllElements Element UID Isolated Locators Available Actions
  • 37. Tellurium Basics: UI Object• uid – unique in UI module• namespace – for future extension• locator – locator of the UI object – A base locator (relative XPath) – A composite locator (object attributes)• group – applied to some kinds of UI objects to switch on grouping locating• respond – define JavaScript events the UI object could respond to• some basic methods – isElementPresent, isVisible, isDisabled, waitForEle mentPresent, getText, mouseOver, mouseOut, ge tAttribute
  • 38. Tellurium IDE and TrUMP
  • 39. DEMO
  • 40. Tips and Tricks• Create elements when first need them• Review and improve elements continuously• Isolate and hide hacks inside elements• Use open source libraries as basis• Use annotations and other metadata techniques to simplify creation
  • 41. What we have at the end of long way?RESULTS ANALYSIS
  • 42. Long Path Bring Us to…• Reliable tests• Reusable test code• Separation of concepts• Expressive tested UI structure• Short and clear tests• Tests look more like acceptance tests• Tests are understood by non-technical people
  • 43. Company DSL LibraryComponents may be reused between different applications and projects inside a company Company AJAX Portal Components Online Store Basic Components Customer Service JSF Components
  • 44. @xpinjection