The Chronicle of iPhone Automation -- From Frank to UISpec to UIAutomation to KIF

Post on 19-Oct-2014

2.824 views 0 download

Tags:

description

 

Transcript of The Chronicle of iPhone Automation -- From Frank to UISpec to UIAutomation to KIF

The Chronicle of iPhone Automation

From Frank to UISpec to UIAutomation to KIF

Hinling YeungQA Automation Engineer from Trulia, Inc

Background

• iPhone app• iPad app• Android app• Mobile site• more phone/device apps to come in a short

future• Mobile traffic keeps increasing

To help maintain our sanity…

Let’s automate some of our devices!

Now let’s get back to the topic.

• After watching Pete Hodgson’s presentation about Frank, I was very hopeful about iPhone automation…

Then I follow the online documentations…

• And successfully setup up Frank!

However, when I actually start automating my first test case.

I hit my first wall:

mbp-1350:cucumber hyeung$ cucumber features/login.feature Feature: As an iOS developer I want to click the Log in button So I can see the warning message of missing email address and password

Scenario: # features/login.feature:6

PING FAILED!!!!FRANK! Given I launch the app # features/step_definitions/launch_steps.rb:1 When I wait 30 seconds # features/step_definitions/frank_steps.rb:1 When I touch the "No Thanks" Button # features/step_definitions/frank_steps.rb:29 end of file reached (EOFError) /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/protocol.rb:135:in `sysread' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/protocol.rb:135:in `rbuf_fill' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:62:in `timeout' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:93:in `timeout' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/protocol.rb:134:in `rbuf_fill' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/protocol.rb:116:in `readuntil' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/protocol.rb:126:in `readline' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:2020:in `read_status_line' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:2009:in `read_new' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:1050:in `request' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:543:in `start' ./features/step_definitions/frank_steps.rb:30:in `/^I touch the "([^\"]*)" Button$/' features/login.feature:9:in `When I touch the "No Thanks" Button'

Failing Scenarios:cucumber features/login.feature:6 # Scenario:

1 scenario (1 failed)3 steps (1 failed, 2 passed)0m37.113s

So…

• Keep on debugging the ruby scripts, Frank, and possibly UISpec

• OR

• Let’s get to the bottom: UISpec

Then I start setting up UISpec…

• adding libraries…• Adding dependencies…• Adding header files…• Adding more header files…• Oops…linking error. Then adding .m files…• Add some test code:

-(void)itShouldShowErrorMessageAfterClickingLogInButton { [[app.find.label text:@"For Sale"] flash]; [[app.find.label text:@"For Rent"] flash]; [[app.find.label text:@"My Trulia"] flash]; …}

Looks Really Promising…• Let’s try “touch” it instead of just “flash” it.• Then I hit another wall:

• “touch” results in no reaction or EXC_BAD_ACESS error

Sigh…

I really need something that just work!

• Then I talked to a friend of mine who works in the MobileMe automation team in Apple:

Me: What do you use to automate your iphone app?Friend: JavascriptMe: Javascript? You mean Javascript JAVASCRIPT? The one we use on the

browser?Friend: yes. Check the apple dev center.

• Results: UIAutomation from Apple

UIAutomation with Instruments

• http://alexvollmer.com/posts/2010/07/03/working-with-uiautomation/

• Add some accessibilityLabels• Setup the Instruments template• Write some Javascript• A little counter intuitive but click “record” and

it starts running.• And it works!

Let’s integrate the tests with Jenkins

• I hit another wall:

• There is no good way to kick off the tests from command line and integrate my results to Jenkins!

Then I found KIF…

• KIF – Keep It Functional• By Square (Eric Firestone) --

https://github.com/square/KIF• Blog:

http://corner.squareup.com/2011/07/ios-integration-testing.html

• Couple linking errors later…

YEAH!

• It actually works from end to end with simple enough setup.

• With instructions to start the test in command line

• And quits after the test finish running.• And output results to the console.• Results are not in a CI-ready format but

THAT’S OK IF THAT’S THE ONLY PROBLEM!

Final Solution

• KIF• Add accessibilityLabel to textField, Button, and

View• isAccessibilityElement = YES• Symbiote from Frank to inspect the labels on

app• WaxSim to launch app from command line• Modify the KIF log to output test results that

can be turned into standard junit result format