DSL, Page Object and Selenium – a way to reliable functional tests
- 1. DSL, Page Object and Selenium – a way to reliable functional tests Mikalai Alimenkouhttp://xpinjection.com26.02.2011
- 2. BackgroundJava Technical Lead/Scrum Master at Zoral Labs6+ years in software development4+ years of working by Agile methodologiesExpert in Agile engineering practicesAgile coach (TDD, Testing, Planning, etc.)at XP Injection (http://xpinjection.com)
- 7. Selenium Tests Issues: Verbosexpath=//input[@value=‘continue’]browser.enter…browser.click…css=#results dip p.firstbrowser.getXpathCount…id=greenButtonbrowser.waitForPageToLoad…browser.check…
- 10. Selenium Tests Issues: Fragilebrowser.click("//input[@id=(//label[text()='Fax']/@for)] ");What is going on here?browser.getText(“//div[@id='App']/div/p[4]/div[1]/h4[@class='Online']”);Depends too much on page structure!
- 12. What is the Primary Goal?To enable reliable stable tests we need to separate all parts as much as possible
- 15. Definition of DSLA 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).
- 18. Benefits of DSL ApproachHigh-level – tests are in the language of product management, at the user levelReadable – product management can understand themWritable – easy for developer or QA to write new testExtensible – tests base is able to grow with DSL
- 19. Tips and TricksUse test class hierarchy or test helpersUse builders, visitors and other design patternsReuse domain model from applicationSome common methods move to base test classMinimize usage of browser instance in tests
- 21. Page Object PatternIndex PageordersearchSearch PageloginsearchfilterMain Pageopensee moreDetails Pagecloseshow me like this
- 24. Ways to Implement Page ObjectDuplicate Site Mapwith Packages and ClassesMove Site Structure to UI-Element
- 26. Tips and TricksAllow chain invocationsBasic page with browser details and common methodsExpose only what is allowed to see or do on the pageDon’t use browser instance in tests at allUse static analysis to check rulesUse site map to prepare Page Objects
- 34. Tellurium Basics: UI ModuleGroovy FileCan Build Xpath in RuntimeAll ElementsElement UIDIsolated LocatorsAvailable Actions
- 35. Tellurium Basics: UI Objectuid– unique in UI module namespace – for future extensionlocator – locator of the UI objectA base locator (relative XPath)A composite locator (object attributes)group – applied to some kinds of UI objects to switch on grouping locatingrespond – define JavaScript events the UI object could respond tosome basic methods – isElementPresent, isVisible, isDisabled, waitForElementPresent, getText, mouseOver, mouseOut, getAttribute
- 38. Tips and TricksCreate elements when first need themReview and improve elements continuouslyIsolate and hide hacks inside elementsUse open source libraries as basisUse annotations and other metadata techniques to simplify creation
- 40. Long Way Bring Us to…Reliable testsReusable test codeSeparation of concepts Expressive tested UI structureShort and clear testsTests look more like acceptance testsTests are understood by non-technical people
- 41. Company DSL LibraryComponents may be reused between different applications and projects inside a companyAJAX ComponentsCompany PortalBasic ComponentsOnline StoreJSFComponentsCustomer Service