UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
DSL, Page Object и WebDriver – путь к надежным функциональным тестам
1. DSL, Page Object and WebDriver –
the path to reliable functional tests
Mikalai Alimenkou
http://xpinjection.com
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 (http://xpinjection.com)
• Organizer of Selenium Camp, JEEConf and
XP Days Ukraine conferences
10. Selenium Tests Issues: Fragile
driver.findElement(By.xpath("//input[@id=(//label[tex
t()='Fax']/@for)]")).click();
What is going on here?
driver.findElement(By.xpath("//div[@id='App']/div/p[4]/di
v[1]/h4[@class='Online']")).getText()
Depends too much on
page structure!
11. Even More Hidden Issues
Test code
duplication
Hard to
understand No reuse
Fewer 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
Clarity
Test Test
Data Logic
Flexibility
Application
Maintainability
Driver
Stability
13. Ideal Testing Framework
Test Logic Test Data
Storage
DSL Application Driver
Technical Driver Technical
Data Storage
Application Under Testing
15. Definition of DSL
A domain-specific language (DSL) is a
programming language or specification
language dedicated to a particular problem
domain, that is created specifically to solve
problems 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 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 application
STEP 2: INTRODUCE PAGE OBJECT
21. Page Object Pattern
search order
Index
Page
Search
Page
login
search
filter
Main
Page open
see more
Details
close Page
show me like this
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
36. Tellurium Basics: UI Module
Groovy File
Can Build XPath in
Runtime
All
Elements
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
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 Library
Components may be reused between different
applications and projects inside a company
Company AJAX
Portal Components
Online Store Basic
Components
Customer
Service JSF
Components