jonathanpenn / ui-auto-monkey

UI AutoMonkey is a simple stress testing script for iOS applications that runs in UI Automation and Instruments. Grass fed. Free range.
http://cocoamanifest.net
MIT License
1.47k stars 249 forks source link

tapEvent error - tap point is not within bound of screen #1

Closed elfenlaid closed 11 years ago

elfenlaid commented 11 years ago

Script cause automator to generate an uncaught JS error: tap point is not within bound of screen

Strange thing here is that tap coordinates are valid

for example: target.tapWithOptions({x:"51", y:"399"}, {touchCount:"1", duration:"0.5", tapCount:"1"})

Maybe the issue is somehow connected with custom alert view. (I'm just add UIView to UIWindow by addSubview: to present view)

Although I tried to set tap duration to "0", doesn't fix the issue either.

And one more thing: reproduce this issue a little bit easier on Retina 4-inch simulator. On other kind of simulators script session may succeed with chance near ~70% (7/10), when on retina 4-inch literally every session fails

jonathanpenn commented 11 years ago

Hmm. I'm not able to reproduce this. The script runs fine against all the apps I have, even in the Retina 4-inch simulator.

If you create a blank project from one of the iOS Xcode templates, does the same error occur for you? What version of Xcode are you running?

elfenlaid commented 11 years ago

I'm running 4.5 Xcode version. With a blank project everything runs perfect and I tried to simulate situation with custom alert dialog which show some results.

Here's code https://gist.github.com/3968790 . I'm using a "Single view" project template here.

jonathanpenn commented 11 years ago

Okay, I tried a version of what you sent me and I still can't reproduce the problem. Since I didn't have access to your MPViewController and it's xib file, I just used a plain old UIViewController in my fork of your gist:

https://gist.github.com/3969536

I'm wondering if there's something in your MPViewController that's triggering this problem. Can you try changing your app delegate to use just a plain old view controller like my gist and try again? I want to first figure out if it's your machine or your custom view controller. If the problem goes away using a generic view controller, then that might help us isolate what's happening a little better.

elfenlaid commented 11 years ago

My bad, I forgot to remove project prefix. MPViewController is standart uiviewcontroller that comes with "Single view" project template.

It's a little bit hard to reproduce issue anyway, you need to run script couple of times. But in my case exception appears basically in every script iteration (in best case script manage to pass ~600 events)

May be it's possible to surround tap call with some try/catche block?

jonathanpenn commented 11 years ago

Ah, I see. I'm able to reproduce it now. Not very frequently, though.

So, I'm not really sure, but on a whim I padded the x and y random coordinate generation with one pixel and it seemed to fix it. Running several times got all the way through to 1000 events.

Can you pull down the latest, or make the changes in this commit and then see if that solves it for you?

https://github.com/jonathanpenn/ui-auto-monkey/commit/88cddfb2e30fdf3964551cb8dbcae454af8fc41f

elfenlaid commented 11 years ago

Indeed, tapWithOptions failed with bound coordinate like 320 for X. We can extend logging and wait for result or just directly invoke tap tapWithOptions with invalid params.

tapEvent: function() {
    var tapPoint = { x: this.randomX(), y: this.randomY() };
    try {
        this.target().tapWithOptions(
          tapPoint,
          {
            tapCount: this.randomTapCount(),
            touchCount: this.randomTouchCount(),
            duration: this.randomTapDuration()
        }
        );
    } 
    catch (error) {
        UIALogger.logError(error + " " + tapPoint.x + " " + tapPoint.y);
    }
}

We can remove + 1 here, cause automator accept (0,0) tap point: return Math.floor(Math.random() * 10000) % range + 1;

Or add - 1 like you did: this.target().rect().size.height - 1; & this.target().rect().size.width - 1

So, issue is solved.

And You rock! :) Thanks for maintenance

jonathanpenn commented 11 years ago

You're welcome! Thanks for helping me fix this. :)