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

iOS and Android Acceptance Testing with Calabash - Xcake Dublin

iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Sometimes, you would be forgiven for thinking that testing your apps' user interface is not the most fun bit of the whole process of creation. But as a matter of fact, it is, especially if you use interesting tools that help with the heavy lifting and have a freaky domain specific language that makes it straightforward to specify and automate your test cases.

Roland Gröpmair, a regular face at Xcake, will present to us his latest investigations in this area, as part of his talk iOS and Android Test Automation with Calaba.sh.

http://www.meetup.com/Xcake-Mobile-app-development-with-an-Appley-flavour/events/219080531/

Roland Gropmair

December 09, 2014
Tweet

More Decks by Roland Gropmair

Other Decks in Technology

Transcript

  1. What is Calabash? • Automated acceptance testing of mobile apps

    • Cross-platform (Android & iOS) • Open source - Company called Xamarin backing it
  2. What is Calabash? • Automated acceptance testing of mobile apps

    • Cross-platform (Android & iOS) • Open source - Company called Xamarin backing it • https://github.com/calabash/calabash-ios
  3. What is Calabash? • Automated acceptance testing of mobile apps

    • Cross-platform (Android & iOS) • Open source - Company called Xamarin backing it • https://github.com/calabash/calabash-ios • https://github.com/calabash/calabash-android
  4. Unit Tests • Tests smallest unit of functionality public void

    TestPhoneValidator() { string goodPhone = "(123) 555-1212"; string badPhone = "555 12" PhoneValidator validator = new PhoneValidator(); Assert.IsTrue(validator.IsValid(goodPhone)); Assert.IsFalse(validator.IsValid(badPhone)); } • Mocks and Stubs to simulate behaviour of other objects
  5. Acceptance Tests • Performing tests on the full system (e.g.

    using your web page via a web browser) • Described in plain English
  6. Install • ruby -v -> recommended version 2.0+ • gem

    install calabash-cucumber • cd path-to-my-ios-project
  7. Install • ruby -v -> recommended version 2.0+ • gem

    install calabash-cucumber • cd path-to-my-ios-project • calabash-ios setup
  8. Install • ruby -v -> recommended version 2.0+ • gem

    install calabash-cucumber • cd path-to-my-ios-project • calabash-ios setup • calabash-ios gen
  9. Install • ruby -v -> recommended version 2.0+ • gem

    install calabash-cucumber • cd path-to-my-ios-project • calabash-ios setup • calabash-ios gen • in Xcode, build -cal scheme
  10. Install • ruby -v -> recommended version 2.0+ • gem

    install calabash-cucumber • cd path-to-my-ios-project • calabash-ios setup • calabash-ios gen • in Xcode, build -cal scheme • cucumber
  11. Useful Stuff • export DEVICE_TARGET="iPhone 5s (7.1 Simulator)" • cucumber

    NO_STOP=1 • cucumber -t @current • cucumber -t @~excludedtag
  12. Useful Stuff • export DEVICE_TARGET="iPhone 5s (7.1 Simulator)" • cucumber

    NO_STOP=1 • cucumber -t @current • cucumber -t @~excludedtag • calabash-ios console
  13. Useful Stuff • export DEVICE_TARGET="iPhone 5s (7.1 Simulator)" • cucumber

    NO_STOP=1 • cucumber -t @current • cucumber -t @~excludedtag • calabash-ios console • > start_test_server_in_background
  14. Query Syntax • query(“button") => [ {"class"=>"UIRoundedRectButton", "frame"=>{"y"=>287, "width"=>72, "x"=>100,

    "height"=>37}, "UIType"=>"UIControl", "description"=>"<UIRoundedRectButton: 0x7d463d0; frame = (100 287; 72 37); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x7d46ae0>>"}, {"class"=>"UIRoundedRectButton", "frame"=>{"y"=>215, "width"=>73, "x"=>109, "height"=>37}, "UIType"=>"UIControl", "description"=>"<UIRoundedRectButton: 0x7d3a760; frame = (109 215; 73 37); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x7d3a8a0>>”} ]
  15. • query("button index:0 label”) "find the first button, and then

    inside of that find all labels”. • query("button index:0 label", :text)
  16. Custom Steps - Ruby API • https://github.com/calabash/calabash-ios/wiki/03.5-Calabash- iOS-Ruby-API • query,

    check for existence of elements, wait for elements to exist • keyboard
  17. Custom Steps - Ruby API • https://github.com/calabash/calabash-ios/wiki/03.5-Calabash- iOS-Ruby-API • query,

    check for existence of elements, wait for elements to exist • keyboard • scroll
  18. Custom Steps - Ruby API • https://github.com/calabash/calabash-ios/wiki/03.5-Calabash- iOS-Ruby-API • query,

    check for existence of elements, wait for elements to exist • keyboard • scroll • rotate
  19. Custom Steps - Ruby API • https://github.com/calabash/calabash-ios/wiki/03.5-Calabash- iOS-Ruby-API • query,

    check for existence of elements, wait for elements to exist • keyboard • scroll • rotate • backdoor -> call method in iOS app (implement in app delegate)
  20. Custom Steps - Ruby API • https://github.com/calabash/calabash-ios/wiki/03.5-Calabash- iOS-Ruby-API • query,

    check for existence of elements, wait for elements to exist • keyboard • scroll • rotate • backdoor -> call method in iOS app (implement in app delegate) • macro -> call other step definitions
  21. Tips and Tricks • Resetting app data between scenarios •

    Avoid sleep - use wait instead: And I wait to see "send button"
  22. Tips and Tricks • Resetting app data between scenarios •

    Avoid sleep - use wait instead: And I wait to see "send button" • Wait before you interact with any element
  23. Tips and Tricks • Resetting app data between scenarios •

    Avoid sleep - use wait instead: And I wait to see "send button" • Wait before you interact with any element • Wait after every action to finish
  24. Tips and Tricks • Resetting app data between scenarios •

    Avoid sleep - use wait instead: And I wait to see "send button" • Wait before you interact with any element • Wait after every action to finish • Escape quotes…
  25. Tips and Tricks • Resetting app data between scenarios •

    Avoid sleep - use wait instead: And I wait to see "send button" • Wait before you interact with any element • Wait after every action to finish • Escape quotes… • https://groups.google.com/forum/#!forum/calabash-ios
  26. Other Info • UIKonf talk ‘Unit Testing on iOS’ by

    Tim Brückmann https://speakerdeck.com/tibr/unit- testing-on-ios • http://calaba.sh • https://github.com/calabash/calabash-ios • http://developer.xamarin.com/guides/testcloud/ calabash/introduction-to-calabash/
  27. Summary • Automated Testing - investment that pays off •

    Together with unit testing etc: make changes with confidence (still, manual QA required) • Cross-platform mature toolset • Continuous integration / code coverage