Upgrade to Pro — share decks privately, control downloads, hide ads and more …

One Page to Test them all !

Priti
April 09, 2016

One Page to Test them all !

This is presentation made for Global test retreat conference.(http://gtr.agiletestingalliance.org/)

Priti

April 09, 2016
Tweet

More Decks by Priti

Other Decks in Programming

Transcript

  1. ONE PAGE TO TEST THEM ALL ! Priti Biyani |

    @pritibiyani
 GTR 2016 1 A Cross platform mobile automation framework

  2. U.S. AIRLINE MOBILE APP ๏ iOS, Android, iPad, Blackberry, Windows

    and Mobile Web
 
 ๏ Apple Appstore featured app (Travel)
 2
  3. AUTOMATION ๏ Android 
 Calabash Android 
 ๏ iOS 


    Calabash iOS ๏ Mobile Web 
 Watir Webdriver 
 4
  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
  5. 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
  6. 9 Feature File
 ——————— 
 Given ..
 When .. 


    Then .. Step 
 Definitions Android 
 Pages iOS 
 pages web
 pages PAGE OBJECT MODEL
  7. SOLUTION ANALYSIS ๏ ADDING NEW AUTOMATION? 
 ๏ CODE REUSABILITY?


    ๏ MAKE CHANGE AT ONLY ONE PLACE? ๏ CLASS EXPLOSION 
 
 
 10
  8. 11 Feature File
 ——————— 
 Given ..
 When .. 


    Then .. Step 
 Definitions Single 
 Page
 for each 
 Platform COMMON PAGE OBJECT
  9. SOLUTION ANALYSIS ๏ ADDING NEW AUTOMATION?
 ๏ CODE REUSABILITY ?


    ๏ MAKE CHANGE AT ONLY ONE PLACE ? ๏ CLASS EXPLOSION 
 
 
 12
  10. 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
  11. 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
  12. 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'"
 }
  13. 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

  14. 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

  15. 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
  16. 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

  17. 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()
  18. 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? ()

  19. 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
  20. 23 Feature File
 ——————— 
 Given ..
 When .. 


    Then .. Step 
 Definitions ONE PAGE OBJECT MODEL page page.service element.ui_interaction Driver
  21. 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
  22. 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
  23. 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
  24. TRANSITION ELEMENT 27 @login_button = TransitionElement.new(
 { 
 :web =>

    '#continue_button',
 :ios => "* marked:'Login'",
 :droid => "* marked:'Login'"
 },
 {
 :to => HomePage,
 }
 )
 
 Next Page Class
  25. TRANSITION ELEMENT - MULTIPLE TRANSITION 28 28 Login Admin Home

    Page Member Home Page userType? Adm in M em ber [success]
  26. TRANSITION ELEMENT - MULTIPLE TRANSITION @login_button = TransitionElement.new(
 { 


    :web => '#continue_button',
 :ios => "* marked:'Login'",
 :droid => "* marked:'Login'"
 },
 {
 :to => [AdminPage, UserPage],
 
 }
 )
 
 Multiple Transition
  27. TRANSITION ELEMENT - ERROR TRANSITION Login Admin Home Page Member

    Home Page userType? Adm in [ SUCCESS ] [ FAIL ] M em ber
  28. TRANSITION ELEMENT - ERROR TRANSITION @login_button = TransitionElement.new(
 { 


    :web => '#continue_button',
 :ios => "* marked:'Login'",
 :droid => "* marked:'Login'"
 },
 {
 :to => [AdminPage, UserPage],
 :error => Login
 }
 )
 
 Error Representation
  29. 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.
 

  30. 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
 

  31. 35 LOOK BACK .. Feature File
 ——————— 
 Given ..


    When .. 
 Then .. Step 
 Definitions page page.service element.ui_interaction Driver
  32. 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
  33. SUMMARY ๏ Good OO design is the key 
 ๏

    Good abstractions can help solve hard problems 38
  34. CONCLUSION 39 
 Today, to add automation to support new

    feature development across the three different platforms requires changes in just one place.
  35. 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