jonathanpenn/ui-auto-monkey — pull request #5 by AliSoftware (2013-10-04 12:52:19+00:00)
Title: Converted to dynamic object to be easily #imported and configured

Hi,

As I liked your script and wanted to use it on multiple projects without having to copy/paste it each time, I though being able to `#import "UIAutoMonkey.js"` and then configure and run it would be nice.

With your version you have to change the `config` object inside your source to tweak the configuration. And methods dedicated to "Events" are not clearly isolated from the rest.

My suggestion is to make your script more generic so that we now can simply `#import "UIAutoMonkey"` at the top of our Instruments UIAutomation script, then create a new monkey, configure it and release the monkey at the end, without the need to copy/paster then edit the original source but simply import it and configure it separately

```javascript
#import "UIAutoMonkey.js"

// Configure the monkey: use the default configuration but a bit tweaked
monkey = new UIAutoMonkey()
monkey.config.numberOfEvents = 1000;
monkey.config.screenshotInterval = 5;
// Of course, you can also override the default config completely with your own, using `monkey.config = { … }` instead

// Configure some custom events if needed
monkey.config.eventWeights.customEvent1 = 300;
monkey.allEvents.customEvent1 = function() { … }

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

I'm not a master at javascript so feel free to correct my adaptation if needed. Let me know what you think.