SlideShare a Scribd company logo
DSL, Page Object and Selenium – a way to reliable functional tests Mikalai Alimenkouhttp://xpinjection.com26.02.2011
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)
AgendaSelenium tests issuesStep 1: DSL introductionStep 2: Page Object patternStep 3: Page Element patternResults analysis
Selenium TESTS IssuesWhen you have a hammer, everything looks like a nail
Test ComponentsApplication DriverTest DataTestLogic
How Selenium Works?Get BrowserInvokeCommandsProvide DataUse Locators
Selenium Tests Issues: Verbosexpath=//input[@value=‘continue’]browser.enter…browser.click…css=#results dip p.firstbrowser.getXpathCount…id=greenButtonbrowser.waitForPageToLoad…browser.check…
Selenium Tests Issues: Not Expressive
Selenium Tests Issues: Unreadable
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!
Even More Hidden Issues
What is the Primary Goal?To enable reliable stable tests we need to separate all parts as much as possible
Ideal Testing FrameworkTest Data StorageTechnical Data Storage
Step 1: Introduce DSLCreate domain-specific language for your application
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).
DSL Usage Sample
DEMO
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
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
Step 2: Introduce Page ObjectCreate page map for your application
Page Object PatternIndex PageordersearchSearch PageloginsearchfilterMain Pageopensee moreDetails Pagecloseshow me like this
Test Architecture with Page Object
Components ArchitectureIsolatedlogicConceptsseparationEasier supportSimplicity
Ways to Implement Page ObjectDuplicate Site Mapwith Packages and ClassesMove Site Structure to UI-Element
DEMO
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
Step 3: Page ElementsDivide pages on reusable elements
Page Consists of ElementsMenuCheckboxPanelLinkList of Items
Different Page Elements
Why Page Element Pattern?
Inversion of ControlHides the details of browser communicationAfterBeforeExpose methods for what test can see and do
DEMO
Tellurium Project
Tellurium Basics: UI ModuleGroovy FileCan Build Xpath in RuntimeAll ElementsElement UIDIsolated LocatorsAvailable Actions
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
Tellurium IDE and TrUMP
DEMO
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
Results ANALYSISWhat we have at the end of long way?
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
Company DSL LibraryComponents may be reused between different applications and projects inside a companyAJAX ComponentsCompany PortalBasic ComponentsOnline StoreJSFComponentsCustomer Service
Any Questions?

More Related Content

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)
  • 3. AgendaSelenium tests issuesStep 1: DSL introductionStep 2: Page Object patternStep 3: Page Element patternResults analysis
  • 4. Selenium TESTS IssuesWhen you have a hammer, everything looks like a nail
  • 6. How Selenium Works?Get BrowserInvokeCommandsProvide DataUse Locators
  • 7. Selenium Tests Issues: Verbosexpath=//input[@value=‘continue’]browser.enter…browser.click…css=#results dip p.firstbrowser.getXpathCount…id=greenButtonbrowser.waitForPageToLoad…browser.check…
  • 8. Selenium Tests Issues: Not Expressive
  • 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
  • 13. Ideal Testing FrameworkTest Data StorageTechnical Data Storage
  • 14. Step 1: Introduce DSLCreate domain-specific language for your application
  • 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).
  • 17. DEMO
  • 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
  • 20. Step 2: Introduce Page ObjectCreate page map for your application
  • 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
  • 25. DEMO
  • 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
  • 27. Step 3: Page ElementsDivide pages on reusable elements
  • 28. Page Consists of ElementsMenuCheckboxPanelLinkList of Items
  • 30. Why Page Element Pattern?
  • 31. Inversion of ControlHides the details of browser communicationAfterBeforeExpose methods for what test can see and do
  • 32. DEMO
  • 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
  • 37. DEMO
  • 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
  • 39. Results ANALYSISWhat we have at the end of long way?
  • 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