Share
Embed
One Page to Test them all !
This is presentation made for Global test retreat conference.(http://gtr.agiletestingalliance.org/)
Priti
April 09, 2016
Transcript
41 slides
-
ONE PAGE TO TEST THEM ALL ! Priti Biyani |
@pritibiyani GTR 2016 1 A Cross platform mobile automation framework -
U.S. AIRLINE MOBILE APP ๏ iOS, Android, iPad, Blackberry, Windows
and Mobile Web ๏ Apple Appstore featured app (Travel) 2 -
AUTOMATION ๏ Android Calabash Android ๏ iOS
Calabash iOS ๏ Mobile Web Watir Webdriver 4 -
WE SHOULD REMEMBER… ! ๏ Easy to add tests.
๏ Allow Reuse of the code. ๏ Promote high level thinking. ๏ Simple to accommodate changes in framework ๏ Keep it simple. ๏ Keep it simple. 6 -
PROBLEM STATEMENT 8 Create a generic automation framework which
could support each of the three UI automation tools and work seamlessly across both native and hybrid UI screens -
9 Feature File ——————— Given .. When ..
Then .. Step Definitions Android Pages iOS pages web pages PAGE OBJECT MODEL -
SOLUTION ANALYSIS ๏ ADDING NEW AUTOMATION? ๏ CODE REUSABILITY?
๏ MAKE CHANGE AT ONLY ONE PLACE? ๏ CLASS EXPLOSION 10 -
11 Feature File ——————— Given .. When ..
Then .. Step Definitions Single Page for each Platform COMMON PAGE OBJECT -
SOLUTION ANALYSIS ๏ ADDING NEW AUTOMATION? ๏ CODE REUSABILITY ?
๏ MAKE CHANGE AT ONLY ONE PLACE ? ๏ CLASS EXPLOSION 12 -
13 COMMON PAGE OBJECT — CONCERNS Single Page for
each Platform Automation Tools Calabash droid Calabash iOS Watir Different UI actions touch click Locators Navigation Patterns Nav Drawer Menu Bar Tab Bar -
OBJECT MODELING Lets try and do a Object Modeling exercise!
Single page object class ➡ What are the key fields? ➡ What’s the key behavior? 14 -
PAGE IDENTIFIER 15 Page Name : String Id : Map
Identify each page uniquely on the device { :web => "'#login_form'", :ios => "label marked:'LoginPageHeaderLabel'", :droid => "* id:'title_login'" } -
ID EXISTS CHECK 16 def exists? case platform when
ANDROID query(ui_query).empty? when IOS query(ui_query).empty? when WEB Browser.element(:css => locator).present? end end -
DRIVER ABSTRACTION 17 Page Name : String Id : PageId
PageId Field : Map exists? () PageId Driver Platform : droid exists? () Driver Platform: ios exists? () Driver Platform: web exists? () def exists?(id_map) # ----- # DROID SPECIFIC CODE # ----- end def exists?(id_map) # ----- # iOS SPECIFIC CODE # ----- end def exists?(id_map) # ----- # web SPECIFIC CODE # ----- end -
18 COMMON PAGE OBJECT — CONCERNS Single Page for
each Platform Automation Tools Calabash droid Calabash iOS Watir Different UI actions touch click Locators Navigation Patterns Nav Drawer Menu Bar Tab Bar -
ELEMENTS 19 Page Name : String Id : PageId Elements
Element.new({ :web => ‘#save_and_continue_button’, :ios => "navigationButton marked:'DONE'", :droid => "* marked:'Done'" } Element Id: Map click () 19 def click case platform when ANDROID touch(query(locator)) when IOS touch(query(locator)) when WEB Browser.element(:css => locator).click() end end -
ELEMENTS DELEGATE TO DRIVER 20 Page Name : String Id
: Map Elements Element Id : Map Driver : Driver click() 20 Driver Platform: droid exists? click() Driver Platform: ios exists? click() def click(id_map) # ----- # DROID SPECIFIC CODE # ----- end def click(id_map) # ----- # iOS SPECIFIC CODE # ----- end def click(id_map) # ----- # WEB SPECIFIC CODE # ----- Driver Platform: web exists? click() -
MORE ELEMENTS 21 Page Name : String Id : PageId
Element 1: Element Element 2: Element …. 21 Driver Platform : droid exists? click() setText() getText() checked() Textbox setText() getText() id : map Checkbox checked?() check(item) id : map Dropdown select(item) id : map Driver Platform : ios exists? click() setText() getText() checked() Driver Platform : web exists? click() setText() getText() checked() Element Id : Map Driver : Driver exists? () -
22 COMMON PAGE OBJECT — CONCERNS Single Page for
each Platform Automation Tools Calabash droid Calabash iOS Watir Different UI actions touch click Locators Navigation Patterns Nav Drawer Menu Bar Tab Bar -
23 Feature File ——————— Given .. When ..
Then .. Step Definitions ONE PAGE OBJECT MODEL page page.service element.ui_interaction Driver -
PAGE TRANSITION 24 24 Login Home Page def proceed click_login_button
wait_for_user_page_to_load return HomePage.new end [ success ] def <action> click_button wait_for_<next_page>_to_load return <NextPage.new> end -
TRANSITION MODELING 1. driver.click ๏ Driver should be responsible only
for UI interaction. ๏ Driver should not know about higher level abstraction Page. 2. element.click ๏ It will not be applicable to all elements. 3. Transition Aware Element ➡ An element that understands page transitions. 25 -
TRANSITION ELEMENT 26 Page Name : String Id : PageId
Elements Element 26 Driver Platform: droid exists? click() setText() getText() checked() Textbox setText() getText() id : map Checkbox checked?() check(item) id : map Dropdown select(item) id : map Id : Map Driver : Driver Driver Platform: ios exists? click() setText() getText() checked() Driver Platform: web exists? click() setText() getText() checked() exists? () TransitionElement click(item) id : map -
TRANSITION ELEMENT 27 @login_button = TransitionElement.new( { :web =>
'#continue_button', :ios => "* marked:'Login'", :droid => "* marked:'Login'" }, { :to => HomePage, } ) Next Page Class -
TRANSITION ELEMENT - MULTIPLE TRANSITION 28 28 Login Admin Home
Page Member Home Page userType? Adm in M em ber [success] -
TRANSITION ELEMENT - MULTIPLE TRANSITION @login_button = TransitionElement.new( {
:web => '#continue_button', :ios => "* marked:'Login'", :droid => "* marked:'Login'" }, { :to => [AdminPage, UserPage], } ) Multiple Transition -
TRANSITION ELEMENT - ERROR TRANSITION Login Admin Home Page Member
Home Page userType? Adm in [ SUCCESS ] [ FAIL ] M em ber -
TRANSITION ELEMENT - ERROR TRANSITION @login_button = TransitionElement.new( {
:web => '#continue_button', :ios => "* marked:'Login'", :droid => "* marked:'Login'" }, { :to => [AdminPage, UserPage], :error => Login } ) Error Representation -
MULTIPLE TRANSITIONS - WRONG TRANSITION ‣ Scenario: If there is
a bug in code, app transitions to wrong page from list of multiple transitions. ➡ Tests should take care for assertions of correct page, not the framework. -
TRANSITION ELEMENT 33 def wait_till_next_page_loads(next_pages, error_page) has_error, found_next_page =
false, false begin wait_for_element(timeout: 30) do found_next_page = next_pages.any? { |page| page.current_page?} has_error = error_page.has_error? if error_page found_next_page or has_error end has_error ? error_page : next_pages.find { |page| page.current_page?} rescue WaitTimeoutError raise WaitTimeoutError, "None of the next page transitions were found.” end end -
35 LOOK BACK .. Feature File ——————— Given ..
When .. Then .. Step Definitions page page.service element.ui_interaction Driver -
IMPLEMENTATION NOTES ‣ We "require" specific driver class during test
execution. ‣ Page registry, can be queried for page object instances. ‣ PageRegistry.get "Login Page” ‣ Rspec Unit Tests ‣ Rake task to create new page classes. 36 -
SUMMARY ๏ Good OO design is the key ๏
Good abstractions can help solve hard problems 38 -
CONCLUSION 39 Today, to add automation to support new
feature development across the three different platforms requires changes in just one place. -
LINKS TO CODE SAMPLES 1. Github https://github.com/CrossPlatformPageObject/cross-platform-single-page- example
2. Link of the talk given at VodQA Bangalore http://pritibiyani.github.io/blog/speaking-at-vodqa-banglore/ 40