user293895
user293895

Reputation: 1527

UIAutomation iOS debugging

I have an app that I am trying to automatically debug using a shotgun approach (randomly touching the app for a long period of time). I am currently using UIAutomation and this script:

var target = UIATarget.localTarget();
var app = target.frontMostApp();
var window = app.mainWindow();

target.delay(2);

window.tapWithOptions( { x:160.0, y:370.0 } );

target.delay(5);

for(i=0;i<=100000;i++)
{
    xPoint = Math.floor(Math.random()*319+1)
    yPoint = Math.floor(Math.random()*479+1)
    window.tapWithOptions( { x:xPoint, y:yPoint } );
}

This works, but unfortunately when it does eventually crash I have no debugging information that lets me know why, is there anyway I can tie the XCode debugger to this automation?

Upvotes: 3

Views: 1911

Answers (1)

Jonathan Penn
Jonathan Penn

Reputation: 1341

First off, if you don't mind the shameless plug, you might find my UI AutoMonkey project useful. It's a tool that randomly generates events with all kinds of configurability to do what you call "shotgun" testing.

So, to your question, it may be possible to get Instruments to break at the point that the crash happens. It's not using the full debugger, but by using the Allocations instrument we can tell it to enable NSZombie detection.

With your Automation Template open, make sure the application is closed and a trace isn't being recorded. Open the instrument library and drag the Allocations instrument into the timeline. Click the "i" on that instrument and make sure the "Enable NSZombie Detection" checkbox is checked like in:

Enable NSZombie detection

Then, run your app with an automation test poking around and if it crashes with a memory problem, you'll see the allocations instrument show a popup like in:

Finding the Zombie

Click the little arrow in the popup and you'll jump to where the zombie was triggered. The stack at the time of the crash is in the right sidebar. You should be able to double click at any point in that stack and see the Objective C code where the memory crash occurred. There are some great WWDC videos available that walk through how to use the Allocations instrument. I'd recommend checking those out, too.

Upvotes: 6

Related Questions