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

Avoid modifying ui-auto-monkey #14

Open BruceBGordon opened 9 years ago

BruceBGordon commented 9 years ago

Currently if we want to do anything beyond auto-running the monkey we need to comment out the

    // Release the monkey!
    monkey.RELEASE_THE_MONKEY();

And the README.md reminds us to

Make sure you comment out the last line of `UIAutoMonkey.js` if you include it in your project:

I think it is preferable to be able to integrate the monkey without modifying it. It allows us to place modifications in a distinct client layer.

I suggest we let the default behavior stand, but if you want to release the monkey on your own, in your client simply put:

UIAutoMonkeyClientWillReleaseTheMonkey = true;

At the bottom of UIAutoMonkey we can replace

    // Release the monkey!
    monkey.RELEASE_THE_MONKEY();

with

if (typeof UIAutoMonkeyClientWillReleaseTheMonkey == 'undefined' ||  !UIAutoMonkeyClientWillReleaseTheMonkey  ) {
    // the variable is not defined or it's defined and false
   UIAutoMonkey.RELEASE_THE_MONKEY();
}

This change preserves the original ui-auto-monkey intent that one can start using it in a simple straightforward way. If you want to use it with any customization to the config, or the new conditionHandler or ANR facilities you can do so without modifying the source code as delivered from the repo. Instead you can simply put UIAutoMonkeyClientWillReleaseTheMonkey = true; into your client.

jonathanpenn commented 9 years ago

Looks good to me! Since no one chimed in, go ahead with a pull request.