small medium large xlarge

11 Apr 2013, 01:03
Mark Price (3 posts)

Hi Folks,

Just picked up the beta of the book, I’m only about half way through, but good work! I played around with automation in the past and gave up when I couldn’t get it working. This book explains a lot of what I was missing.

I’ve started modifying the original set of tests to work with one our apps, and I’ve got various things working but I’m finding that sometimes events just don’t seem to get sent and then scripts break partway through.

For example. I navigate from screen1 to screen2 by calling goScreen2, which taps a navigation button and takes me to the correct screen. I do a bunch of things, and then call goBack which calls tap on a cell.

goScreen2: function() {
    	var serversButton = this.navigationBar().leftButton();

goBack: function() {
    	var cell = this.window().tableViews()[0].cells()[0];

Sometimes I can call goBack() just once and it works, on other occasions I have to issue a log() before it to make it work, and sometimes I just have to call it two or three times. Almost seems like a timing issue, but I can’t narrow it down.

Another issue I’ve been seeing is typeString() missing the first two characters from a string. The debug output shows that it was called with the full string, but some of it is missing in the simulator. Here’s another example. I have a screen with several cells of text fields. I initially fill them in with a"0xDEADBEEF"); later when I want to update that field I do the following.

//Find and tap the correct cell
//Select All["Select All"].tap();
// Delete text["Delete"].tap();
// Type new string"0xFEEDBEEF");

What I end up with in the text field is FEEDBEEF rather than 0xFEEDBEEF. Its consistent too.

So long story short, is this sort of behavior expected? It seems really flakey at the moment. I’m running Xcode 4.6.1 which seems to include Instruments 4.6. I know my code snippets may be of little help. But hopefully it gives the gist of what I’m doing.

Cheers, Mark.

11 Apr 2013, 17:33
Jonathan Penn (44 posts)

Hey Mark, thanks for the feedback! Hmm. This behavior dropping the first two characters is certainly not expected. We’re on the same Xcode and Instruments versions. It’s not happening to me, either in the sample code for the book, nor on the my own projects that use UI Automation.

Let’s see if we can’t diagnose the problem. When you run the tests from the book’s sample code that use @typeString()@ in NearbyMe, does it work? If not, then that might mean that something is messed up with your dev tools installation. If it does work, then there’s something unique about your app.

Can you put a delay before the line in your tests where you type in the string? I wonder if your UI is doing something funny that confuses the automator.

Let’s start with this and see what happens. If push comes to shove, I’d love to do a screen share to try to figure this out and we can summarize the results here if need be.

16 Apr 2013, 19:18
Mark Price (3 posts)

Hi Jonathan,

Sorry for the delay in getting back to you. It certainly works in NearbyMe. I discovered the delay call just after posting this and started playing around with it.

It seems that in all the cases when an event doesn’t appear to work, if I simply add a delay() of between 0.5 and 1 second before that event everything works swimmingly. So now if it fails first time, I add an delay and then try it again.

Cheers, Mark.

17 Apr 2013, 12:54
Jonathan Penn (44 posts)

Well, I’m glad that works, but it’s an unfortunate solution. If you’re able to reproduce this on a simpler project, file a “bug report”: with Apple. There may be something deeper here to fix.