fonemonkey for iosfiles.meetup.com/2625872/fonemonkeyoverviewkb.pdf · 2 property of gorilla logic....
TRANSCRIPT
Property of Gorilla Logic. Confidential.
Kyle Balogh, Gorilla Logic, Inc.
FoneMonkey for iOS
2 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
Who am I and why am I here?
• Owner of the FoneMonkey for iOS open source
project
– Previously developed complete iOS solutions for clients
while finishing college
• Manage FoneMonkey for iOS forum
3 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
FoneMonkey
• What is FoneMonkey and why is it cool?
• How can you make FoneMonkey be your
very own personal test monkey?
• What is the future of the monkey?
4 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
The FoneMonkey Open Source Project
• Project created and governed by Gorilla Logic
• Source code repository, compiled binaries, and forums
hosted at www.gorillalogic.com/fonemonkey
• GPL (“Copy Left”)
• More than 1,000 registered downloaders
• New features prioritized according to feedback from
user community
• Code contributions from community are welcome!
5 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
Monkey See, Monkey Do
• Records and plays back “higher-level” events
– Does NOT record “Touch Screen 150,200”
– Records “commands” in the context of components
• Touch UIButton “OK”
• Touch “OK”
• Slide UISlider 75
• Drag MyCanvas 20, 30 , 20, 50
• Type “First Name” Fred
• Also records and plays device Shake and Orientation
Change
• Doesn’t yet handle multitouch gestures • Coming Soon!
6 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
You link FoneMonkey into
your app
• Linking FoneMonkey adds the
FoneMonkey console to your
app, and enables recording and
playback
• Console “drops down”
after inactivity timeout
7 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
FoneMonkey Project Setup
1. Duplicate your app build target to create a
FoneMonkey testing target
8 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
FoneMonkey Project Setup
2. Add FoneMonkey to your Project
9 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
FoneMonkey Project Setup
3. Add FoneMonkey to your Testing Target
10 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
FoneMonkey Project Setup
4. Add –all_load linker flag
11 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
FoneMonkey Project Setup
5. Add QuartzCore and libxml required by FoneMonkey
to projectz
12 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
FoneMonkey Project Setup
6. Add /Developer/Library/Frameworks/SenTestingKit
13 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
FoneMonkey Drops Down in Front of
Your Application Window
14 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
Recording
• Start recording by
tapping the Record
button
• Click the More button to
view recorded
commands
• Commands
can be
edited
Editing
Controls
15 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
Anatomy of a Command
• Command (Required)
• Class of component (optional)
• “MonkeyID” of component
(optional)
• Command-specific timeout
• Command-specific arguments
(Optional)
• Arguments have intelligent
defaults -- for example the
center coordinates of a
component
16 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
Component Identification
• Any combination of Component Class and/or
“MonkeyID”
• MonkeyID –
– accessibilityLabel property if it exists
– Intelligent value used if no accessibilityLabel – for example, the
label of a button
– If no value available, FoneMonkey assigns a unique ordinal (eg,
#1) for the instance of the Component Class
• Can become invalid if layout changes between recording and playback
– Can be set programmatically
17 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
Setting the Accessibility Label
• Set accessibilityLabel in code inputField.accessibilityLabel = @”First Name”;
• Or in Interface Builder “Identity Inspector”
18 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
Programmatically Setting MonkeyID
• In the class defintion @implementation MyComponent (FM_Ready)
- (NSString*) monkeyID {
return self.someIdentifyingStringProperty;
}
• Or in a category @implementation MyComponent (FM_Ready)
- (NSString*) monkeyID {
return self.someIdentifyingStringProperty;
}
19 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
Create a Verification Step
• Verify component
existence or String
property value
• Inserting new command
creates Verify
20 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
The Verification Command
• Verifies existence of a
component
• Can also verify any
String property
expression
for an expected value
21 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
Verification failure reported
during playback
• Failures reported in
FoneMonkey console
• Full error in Xcode
console output
22 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
WaitFor Command waits for
true, or timeout
• WaitFor works like Verify
• Can wait for property
value expression
• Waits until condition to
be true or until timeout
• Timeout specified in
milliseconds
• Often used to wait for
return of server results
23 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
Saving Scripts
• Save scripts with the
Save button
• Open with Open button
• Location of saved files
written to Xcode console
24 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
Scripts saved in three formats
• ScriptName.fm – Native Mac property list file.
• ScriptName.m – Ready-to-Run Objective-C OCUnit
Test
• ScriptName.js – Ready-to-Run JavaScript QUnit Test
• Saved in applications Documents directory
• Location of Documents directory written to Xcode
console
25 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
Extend recorded scripts with custom logic
• Scripts are readable, editable, and can also be
created from scratch without recording
• Scripts are saved in three formats
– “Native” fm file – XML editable with Xcode plist editor
– Objective-C – Ready to run with OCUnit
– JavaScript – Ready to run using FM_ENABLE_QUNIT env var
• Scripts can be extended with Objective-C code or
JavaScript
• Scripts can be run “headless” from the command line
26 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
Three Great Ways to Run
• Interactively from FoneMonkey Console
– Scripts stored in you application’s Documents directory
• Generated Objective-C OCUnit Tests
– Automatically launch OCUnit suites upon app startup (you can watch
the tests run)
– Run previously stored FoneMonkey scripts,
– Scripts can be extended with Objective-C and FoneMonkey API
– Can be run “Headless” in continuous integration environments
• Generated JavaScript QUnit Tests
27 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
Objective-C Code Generation
#import <SenTestingKit/SenTestingKit.h>
#import <UIKit/UIKit.h>
#import "FoneMonkeyAPI.h"@interface
Test1 : SenTestCase {
}
- (void) testSomething {
NSMutableArray* array = [NSMutableArray array];
[array addObject:[FMCommandEvent command:@"Touch"
className:@"UITableViewCell" monkeyID:@"TextView" args:
[NSArray arrayWithObjects:@"94", @"29", nil]]];
NSString* lastResult = [FoneMonkeyAPI playCommands:array];
STAssertNil(lastResult, lastResult);
}
“OCUnit” Test Case
28 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
Running Generated Objective-C
• Drag generated Objective-C into Xcode Project
• Add to testing target only
• Tests will run whenever you start your app
• Disable running of tests by removing
libFoneMonkeyOCUnit.a
29 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
Generated Objective-C
• Creates an array
• Populates array with FMCommandEvents
• Runs the commands
• Returns nil if successful or error message otherwise
30 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
Adding logic to generated code
- (void) testSomething {
NSMutableArray* array = [NSMutableArray array];
for (int i=0; i<10; i++) {
[array addObject:[FMCommandEvent command:@"Touch"
className:@"UITableViewCell”
monkeyID:@"TextView"
args: [NSArray arrayWithObjects:@"94”,
@"29", nil]]];
}
NSString* lastResult = [FoneMonkeyAPI playCommands:array];
STAssertNil(lastResult, lastResult);
}
31 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
JavaScript Code Generation
$(document).ready(function(){
module("sliderTest Module");
asyncTest("sliderTest Test", function() {
// Build the command list
FM.commandList.add("Touch", "UITableViewCell", "Controls", "124", "35");
FM.commandList.addRetry("TouchLeft", "UINavigationBar", "Controls", "500",
"100", null);
// Execute the command list
FM.commandList.play(continuationFunction);
})
function continuationFunction(){
// Additional logic after commands are done playing
}
});
32 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
Running Generated JavaScript (QUnit)
33 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
Running “Headless” in automated builds
• Copy test target and add “Run Script” phase
• Copy & paste script from FoneMonkey documentation
34 Property of Gorilla Logic. Confidential and privileged.
Any unauthorized review, use, disclosure or distribution is prohibited
How can I get my very own Monkey?
• FoneMonkey is free and open source
• Licensed under the GPL (“Copyleft”)
• Available for download at
www.gorillalogic.com/fonemonkey
– Free registration required
• Gorilla Logic provides training, quickstarts, and
customization services
– We can also write software for you, with you, or show you how to
do it better yourself