ios and android acceptance testing with calabash - xcake dublin

64
Acceptance Testing with Calabash @roland9 [email protected] Xcake Dublin, 9th Dec 2014

Upload: roland99

Post on 12-Jul-2015

298 views

Category:

Software


2 download

TRANSCRIPT

Page 1: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Acceptance Testing with Calabash

@roland9 [email protected]

Xcake Dublin, 9th Dec 2014

Page 2: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

What is Calabash?

Page 3: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

What is Calabash?• Automated acceptance testing of mobile apps

Page 4: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

What is Calabash?• Automated acceptance testing of mobile apps

• Cross-platform (Android & iOS)

Page 5: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

What is Calabash?• Automated acceptance testing of mobile apps

• Cross-platform (Android & iOS)

• Open source - Company called Xamarin backing it

Page 6: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

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

Page 7: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

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

Page 8: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Others

• Frank, KIF, Zucchini, UIAutomation, iCuke, …

Page 9: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Why would I do it?

Page 10: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Why would I do it?

Page 11: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Why would I do it?

Page 12: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Other Testing Methods

• Unit Tests

• Integration Tests

• Acceptance Tests

Page 13: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

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

Page 14: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Integration Tests

• Verify that combined modules function correctly

Page 15: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Acceptance Tests

• Performing tests on the full system (e.g. using your web page via a web browser)

• Described in plain English

Page 16: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

How does it work?

• http://blog.lesspainful.com/2012/03/07/Calabash-iOS/

Page 17: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Install

Page 18: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Install• ruby -v -> recommended version 2.0+

Page 19: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Install• ruby -v -> recommended version 2.0+

• gem install calabash-cucumber

Page 20: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Install• ruby -v -> recommended version 2.0+

• gem install calabash-cucumber

• cd path-to-my-ios-project

Page 21: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Install• ruby -v -> recommended version 2.0+

• gem install calabash-cucumber

• cd path-to-my-ios-project

• calabash-ios setup

Page 22: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Install• ruby -v -> recommended version 2.0+

• gem install calabash-cucumber

• cd path-to-my-ios-project

• calabash-ios setup

• calabash-ios gen

Page 23: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

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

Page 24: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

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

Page 25: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

If all goes well:

• LPSimpleExample[11298:13703] HTTPServer: Started HTTP server on port 37265

Page 26: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Build Directory• export APP_BUNDLE_PATH=/Users/rolandgr/

<…>/Build/Products/Debug-iphonesimulator/<…>-cal.app

Page 27: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Gherkin

• https://github.com/calabash/calabash-ios/wiki/01-Getting-started-guide

Page 28: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

• Given …

• When …

• Then …

• And …

Page 29: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Useful Stuff

Page 30: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Useful Stuff • export DEVICE_TARGET="iPhone 5s (7.1 Simulator)"

Page 31: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Useful Stuff • export DEVICE_TARGET="iPhone 5s (7.1 Simulator)"

• cucumber NO_STOP=1

Page 32: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Useful Stuff • export DEVICE_TARGET="iPhone 5s (7.1 Simulator)"

• cucumber NO_STOP=1

• cucumber -t @current

Page 33: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Useful Stuff • export DEVICE_TARGET="iPhone 5s (7.1 Simulator)"

• cucumber NO_STOP=1

• cucumber -t @current

• cucumber -t @~excludedtag

Page 34: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Useful Stuff • export DEVICE_TARGET="iPhone 5s (7.1 Simulator)"

• cucumber NO_STOP=1

• cucumber -t @current

• cucumber -t @~excludedtag

• calabash-ios console

Page 35: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

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

Page 36: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

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>>”}

]

Page 37: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

• query("button index:0 label”)

"find the first button, and then inside of that find all labels”.

• query("button index:0 label", :text)

Page 38: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

• touch("tabBarButton index:1")

Page 39: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

accessibilityLabel accessibilityIdentifier

Page 40: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Custom Steps - Ruby API

Page 41: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Custom Steps - Ruby API• https://github.com/calabash/calabash-ios/wiki/03.5-Calabash-

iOS-Ruby-API

Page 42: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

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

Page 43: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

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

Page 44: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

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

Page 45: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

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

Page 46: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

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)

Page 47: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

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

Page 48: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

http://www.slideshare.net/mobiletestsummit/ios-automated-testing-with-calabash-tips-and-tricks?qid=0afecec1-fe64-4168-bb69-a548bd01b832&v=default&b=&from_search=8

Page 49: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Tips and Tricks

Page 50: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Tips and Tricks• Resetting app data between scenarios

Page 51: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Tips and Tricks• Resetting app data between scenarios

• Avoid sleep - use wait instead:

Page 52: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Tips and Tricks• Resetting app data between scenarios

• Avoid sleep - use wait instead:

And I wait to see "send button"

Page 53: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

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

Page 54: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

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

Page 55: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

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…

Page 56: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

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

Page 57: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Optional: Compare Images

• gem install imagemagick-binaries

• check you have compare: $ which compare

Page 58: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Optional: Compare Images

• gem install imagemagick-binaries

• check you have compare: $ which compare

Page 59: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Continuous Integration

Page 60: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Code Coverage

Page 61: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

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/

Page 62: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

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

Page 63: iOS and Android Acceptance Testing with Calabash - Xcake Dublin
Page 64: iOS and Android Acceptance Testing with Calabash - Xcake Dublin

Acceptance Testing with Calabash

@roland9 [email protected]

Xcake Dublin, 9th Dec 2014