UI AutoMonkey is a simple to set up stress testing tool for iOS applications. You can pound on your app until it wilts with a barrage of taps, swipes, device rotations, and even locking and unlocking the home screen! Watch the app’s performance characteristics with Instruments, discover race conditions, or just enjoy watching your work under butt dialing conditions.
There’s nothing special to install since this leverages UI Automation and Instruments that come with Apple’s developer tools. If you have Xcode, you’ve got all you need to stress test your applications with UI AutoMonkey. Follow the instructions below to set up a UI Automation Instruments template with the UIAutoMonkey.js script.
First, load up your app in Xcode. Choose “Profile” from the “Product” menu (or press Command-I) to build your application and launch the Instruments template picker.
Next, you’ll want to pick the “UI Automation” template. You can add in other instruments to measure the app’s performance under the test after we set up the basic automation template.
Switch to the script pane by choosing “Script” from the dropdown menu in the middle dividing bar of the Instruments document.
Create a script in this Instruments document by choosing “Create. ” from the “Add” button on the left sidebar.
Paste in the UIAutoMonkey.js script. Feel free to adjust the configuration parameters to taste. You’ll find more discussion about them below.
At this point you can simply click the playback button at the bottom of the Instruments window to start the script. Boom. The monkey lives.
Once you’ve set up UI AutoMonkey in your Instruments document, you can create a custom template tied to this application that you can double click to run. First, make sure the Instruments document is stopped by clicking the red record button in the upper left of the Instruments document. Then choose “Save As Template. ” from the “File” menu and choose where to put the file. Now, you can double click this template to open Instruments with the UI AutoMonkey script already embedded. Just click the red record button in the upper left of the Instruments document and the app will launch and run.
Configuration and Beyond
For simplicity’s sake, the tool is just a single script you paste into a UI Automation template for your application. You could wire it up in a command line workflow if you want, but that would take a bit more effort than you need to just get it running.
numberOfEvents is pretty straightforward. It’s how many events will happen to your application.
delayBetweenEvents controls how many seconds (or fractions of seconds) the script waits before triggering the next random event. You might want to tweak this to taste. The script triggers events directly on the UIATarget so there is no natural timeout that you might be familiar with when interacting with UIAElements . The script will pummel the app with events as fast as it can generate them if you want it to.
eventWeights are relative weights to determine how often an event gets triggered. If the tap event is 100, and orientation is 1, then a tap is 100 times more likely to occur than a device orientation. Adjust these to match the best set of events for your application.
touchProbability controls the different kinds of tap events. By default, a tap is just a single tap. Adjust these settings to set how often a double tap or long press occurs. Each of these values must be between 0 and 1.
Running on device, the script may fail with a vague message: “An error occurred while trying to run the script.” Make sure that under the Developer menu in device settings, the “Enable UI Automation” option is toggled on.
Save UIAutoMonkey.js somewhere in your disk to import it and configure it in each of your Instruments instances
In your test file
You will need to adjust the imports to the path for UIAutoMonkey.js and the optional buttonHandler.js files
###SetGlobals.js Have at least this global there:
When the monkey is released using the default release mechanism (UIAutoMonkeyClientWillReleaseTheMonkey is undefined or false) it executes
and you will see this in the trace log. If your customization are not taking effect make sure that the entry “Release the monkey directly from UIAutoMonkey” is not in the trace log.
Check out the built in events for more information and the helper methods available to you.
(Special thanks to Oliver Halligon for the new customization features!)
After enjoying your monkey for a while you may notice some situations that require some intervention.
If you run your monkey for a specific number of events it’s not clear just how long it will run for. Each event might take a little while to process. If you run for a long time the imprecision adds up.
The above will run the monkey for
8 hours. Every 60 events it will check the time (for efficiency it doesn’t check every event). To avoid ambiguity if you want to run in minutes you must turn off monkey.config.numberOfEvents by setting it to 0 or false .
At times your playful monkey will enter a page from which it rarely escapes. Perhaps the only way out is a little “X” button on the top right, and until that is pressed the monkey will remain on the page. This may prevent your monkey from fully visiting your application. Wouldn’t it be nice to tell the monkey “Check every so often and if there’s an “X” button press it”?
The monkey has a notion of condition handlers. The monkey is not too smart, but condition handlers let you add clever behavior.
This instructs the monkey that every 10 events it will check to see if there is a visible Back button on the navigation bar, and if so press it.
You can add as many handlers as you want. ButtonHander is just a specific type of handler that is ready to rumble with the Monkey, but you can add other types of handlers as long as they conform to the conditionHandler protocol defined in UIAutoMonkey.
Now the conditionHandlers are processed right in the monkey’s inner loop, so it is usually prudent to not check the handlers on every single event. That would be inefficient, and furthermore you don’t want to jump out of UI Holes immediately: we want to linger for a while. The second parameter is how often (in event units) to check if the buttonHander’s condition isTrue() . The 3rd parm is true if the button descends from the navigation bar, or false if it is a top level button.
If you need more advanced detection you can add an optional 4th parameter, the optionalIsTrueFunction . This can be used for more advanced detection if the condition is true.
ConditionHandlers (remember, a ButtonHandler is a type of conditionHandler) have an isExclusive() method. If true, and if the condition is true, then no other conditions are considered for the current pass. ButtonHandlers always return true for isExclusive() .
On pass 9 through the monkey neither handler will be considered beause 9 is not a multiple of 10.
One pass 10 through the monkey lets assume that there is a “Back” button visible on the navigation bar. The monkey will invoke the first buttonHandler, it will indicate that it finds a button. The monkey will ask the handler to handle() the condition, and finally it will ask the handler if it isExclusive() to which it will return true . The monkey will then skip any other handlers for event 10, so it will not invoke the Done buttonHandler.
For efficiency the most popular exclusive handlers should be placed first. At the end of the monkey run statistics are logged that indicate how often each handler returned true .
Application Not Repsonding (“ANR”)
Sometimes your application may stop responding, but our playful monkey doesn’t care. Hours can pass while the monkey thinks it’s tapping, dragging etc. when in reality the application is frozen.
This becomes worse when our monkey is connected to an unattended continuous integration server. The monkey run may finish and erroneously report success. What’s need is some way to detect ANR condtions and fail the monkey.
The monkey can check to see if the application is progressing. It does this by using a fingerprintFunction to document the state of the application. If the state of the application fails to change the monkey can declare an ANR.
The fingerprint function is supplied by the client. One handy, free fingerprint function is elementAccessorDump() found in the open source Tuneup.js. This function creates a logical textual description of the main view.
The above will take a current snapshot every 180 events using the fingerprintFunction. If it is the same as the prior snapshot and if that’s been the case for more than 1800 events, then an exception will be thrown and the monkey will stop. Otherwise the current snapshot will become the prior snapshot.
At the end of the run statistics are logged indicating the max number of events that the snapshot was identical, and what the monkey.config.anrSettings.eventsBeforeANRDeclared was. You can use this to see how close the system was to throwing an ANR exception.
To make the most out of this, you’ll want to level up on Instruments, Apple’s official tool for evaluating usage and performance of your applications. Check out session 409 from the WWDC 2012 sessions (included for free with an Apple developer account), for more information.
To learn more about UI Automation, check out my collection of resources on cocoamanifest.net.
Feel free to fork the project and submit a pull request. If you have any good ideas to make this easier to set up for new users, that would be great! I’m also looking for a good avatar to represent our fine monkey. Got some graphic skills?
UIAutoMonkey is available under the MIT license. See the LICENSE file for more info.
UI AutoMonkey is a simple stress testing script for iOS applications that runs in UI Automation and Instruments. Grass fed. Free range.
UI AutoMonkey is a simple stress testing script for iOS applications that runs in UI Automation and Instruments. Grass fed. Free range. – jonathanpenn/ui-auto-monkey
Search Location or USE LOCATION
Distance Range Radius: KM
Get Your Directions
At Grease Monkey®, We Value
Your Business-And Your Time!
When you visit Grease Monkey® for a Full-Service Oil Change, we’ll complete your service in the time we promise. If our Certified Pit Crew doesn’t finish in the time promised or less, you’ll get a buck back for every minute we go over. That’s our service commitment to you.
A “Full” Synthetic Oil will be 100% synthetic with no blended oil mixture. Full Synthetic Oil should be used if your manufacturer requires it, and if you are looking for premium performance and protection. Full Synthetic Oil will perform better in extreme climates that have really high or low temperatures. You should consider Synthetic for “severe” driving conditions, like stop-and-go or a lot of towing.
Using a combination of regular and synthetic motor oil, Synthetic Blend oils will offer improved engine protection during cold starts and help prevent oil breakdown. A blend will reduce oil consumption and evaporative loss. Your Grease Monkey Pit Crew will help you evaluate if a Synthetic Blend is right for your vehicle.
Uses a combination of regular and synthetic motor oil specifically formulated for high-mileage vehicles that are over 75,000 miles. High mileage oils are professionally formulated to help protect critical engine parts. Help fight sludge and varnish deposits, as well as stop viscosity breakdown. They include seal conditioners to help prevent leaks.
Economy oil will meet most owner’s manual specifications. As a basic oil with some chemical additives, it should be noted that driving conditions have an impact on the oil you may want to use as well as how often you change your oil. Grease Monkey will help you weigh those options. Some vehicles now require synthetic oils per their specifications, and the basic oils will not meet your manufacturer’s warranty.
We’ve updated our privacy and cookies policy.
Not only does Grease Monkey care about your car, we care about you. With our Pit Crew Guarantee, you will be back on the road in the quoted time or we will give $1 for every minute we go over. GET IN. GET OUT. GET GOING.™