Bendyworks

What's happening in

Never trust developers who don't embrace their inner geek. We're actively engaged in the pro­gram­ming world, and have plenty to say and share on the subjects that ex­cite us. Consider this our simul­taneous soapbox, corkboard, and scrapbook for all things geeky.

Tutorial

Posted on 02.02.12 by Jaymes |

UIAutomation and Pusher

UIAutomation is Apple’s answer to integration tests. It allows you to drive and run assertions against your application using a javascript library that interacts with user interface elements. It’s great to have such a powerful tool, but what if you have an application that depends on external triggers, such as Pusher events?

Let me introduce you to UIAHost. More specifically, it’s method performTaskWithPathArgumentsTimeout. What this allows you to do is execute a script in the flow of your tests.

Say we want to execute the ruby script:

All we have to do in our UIAutomation script is this:

That’s a pretty simple ruby script, and will fail to find the pusher gem on any of our machines at Bendyworks because we use RVM. So what we need to do is load RVM into the environment (explained further here):

RVM is loaded, now we can set the gemset like so:

Now our simple ruby script has evolved into a bash script in order to load the correct ruby environment and our gemset along with it. Now how are we going to execute a ruby script with it? Well, we could assign our ruby into a bash variable then run it with ruby -e like so:

Wonderful! Now we can trigger a pusher event from our automation code and then assert that our app does what it’s supposed to.

Here is the script in all its glory: