Escort Missions Logo

Escort Missions

You ever get the feeling that life is just one long series of Escort Missions?

UI Automation App Input

So, I’ve been doing more UI Automation test work, and I’ve discovered a couple of things. I’m kind of trying to write them up as I run into them, although I’m putting together a helper library that I’ll announce at some point, hopefully soon.

So, what I’m trying to work on is a race condition in my KidChart app. The issue (I think) has to do with notifications during input into an UISearchBar.

So, I got to the right screen (more on that later), and tried searchBar.setValue(“Ate 2 Vegetables!”), but it turns out that if you run “.setValue()”, none of the delegate events fire, so I had to use the Keyboard.

I didn’t expect using the keyboard to be nearly as hard as it turned out to be. I can’t figure out an intuitive way to change keyboard modes (I expected there to be a key called something like “Shift” that you could hit to get capital letters. No such luck), so I ended up having to do it the hard way. This is what I ended up with to type in the string in setValue() above:

 

1var searchbar = view .searchBars()[0]; 2searchbar .tap(); 3 4if (searchbar .hasKeyboardFocus()) { 5 UIATarget .localTarget().delay(1); 6 7 UIATarget .localTarget().tap({x :20,y :400}); //Hit Shift for Capital Letters 8 UIATarget .localTarget().delay(1); 9 10 UIATarget .localTarget().frontMostApp().keyboard().keys().firstWithName(“A”).tap(); 11 UIATarget .localTarget().frontMostApp().keyboard().keys().firstWithName(“t”).tap(); 12 UIATarget .localTarget().frontMostApp().keyboard().keys().firstWithName(“e”).tap(); 13 UIATarget .localTarget().frontMostApp().keyboard().keys().firstWithName(“space”). 14
tap(); 15 UIATarget .localTarget().tap({x :20,y :460}); //Select Number Keyboard 16 UIATarget .localTarget().delay(1); 17 UIATarget .localTarget().frontMostApp().keyboard().keys().firstWithName(“2”).tap(); 18 UIATarget .localTarget().frontMostApp().keyboard().keys().firstWithName(“space”). 19
tap(); 20 UIATarget .localTarget().frontMostApp().keyboard().keys().firstWithName(“v”).tap(); 21 UIATarget .localTarget().frontMostApp().keyboard().keys().firstWithName(“e”).tap(); 22 UIATarget .localTarget().frontMostApp().keyboard().keys().firstWithName(“g”).tap(); 23 UIATarget .localTarget().frontMostApp().keyboard().keys().firstWithName(“e”).tap(); 24 UIATarget .localTarget().frontMostApp().keyboard().keys().firstWithName(“t”).tap(); 25 UIATarget .localTarget().frontMostApp().keyboard().keys().firstWithName(“a”).tap(); 26 UIATarget .localTarget().frontMostApp().keyboard().keys().firstWithName(“b”).tap(); 27 UIATarget .localTarget().frontMostApp().keyboard().keys().firstWithName(“l”).tap(); 28 UIATarget .localTarget().frontMostApp().keyboard().keys().firstWithName(“e”).tap(); 29 UIATarget .localTarget().frontMostApp().keyboard().keys().firstWithName(“s”).tap(); 30

31 UIATarget .localTarget().tap({x :20,y :460}); //Select Number Keyboard 32 UIATarget .localTarget().delay(1); 33

34 UIATarget .localTarget().tap({x :20,y :400}); //Now Select Symbol Keyboard 35 UIATarget .localTarget().delay(1); 36 37 UIATarget .localTarget().frontMostApp().keyboard().keys().firstWithName(“!”).tap(); 38 39} else { 40 UIALogger .logFail(“Could not activate the Search Bar”); 41}

 

That’s all going into a library – so my tests won’t actually look like that, but I needed to do it by hand once to figure out what to put in the library. And I figured it was the best thing to throw into the blog here to illustrate the technique – so you don’t have to figure it out for yourselves (and I don’t have to figure it out again).

Happy Testing.