4

I am very new to IOS programming. I have a task to find if I can automate my UI for testing. This is what I want to do:

  • Put some code in my application that randomly (sounds bad but may be pre-defined events)sends event messages to controls on the screen.

  • Since it is just code I should be able to take the app, deploy it in any iPhone or iPad and run the program.

  • Once the app is completely automated by my code I guess it will be easy to do the analytics on the obtained performance data.

I have seen FoneMonkey but looks like it needs user interaction recorded manually on each device.

Any thoughts or suggestions are welcome.

  • Lalith
dtuckernet
  • 7,817
  • 5
  • 39
  • 54
Lalith
  • 19,396
  • 17
  • 44
  • 54
  • 1
    have you tried UI Automation in Instruments? http://developer.apple.com/library/ios/#documentation/DeveloperTools/Reference/UIAutomationRef/ – Felix Jul 21 '11 at 22:40

7 Answers7

5

Hello Lalith i have been creating some UI Automation tests for an application and its working very well. Although it has some tricks, I think you should take a look at these links:

http://answers.oreilly.com/topic/1646-how-to-use-uiautomation-to-create-iphone-ui-tests/

http://alexvollmer.com/posts/2010/07/03/working-with-uiautomation/

If you need more help, just let me know. :)

Edit1:

On your viewDidLoad of your viewController you can add something like this:

   - (void)viewDidLoad {
        [super viewDidLoad];
        //(Your code...)
        // I set it to start after 5 seconds...
        [self performSelector:@selector(startTest) withObject:nil afterDelay:5];
     }


   -(void)startTest{
      //took this from the link you posted
      [myButton sendActionsForControlEvents:UIControlEventTouchUpInside];
    }

Edit 2:

if([myTextField canBecomeFirstResponder]){
    [myTextField becomeFirstResponder];
}
Rui Peres
  • 25,741
  • 9
  • 87
  • 137
  • Thanks.. I'll checkout all tools. Once I get familiar with the stuff I would probably create a small framework myself.. For now I am trying hard to understand basics. – Lalith Jul 22 '11 at 00:26
  • Jacky, I figured that any UI automation tools we use cannot be run in actual device without connecting to the host machine. I am looking at sendActionsforControlEvents under UIControl class.. All I need to do is perform the click action or what ever... It'd be great if you know of any references – Lalith Jul 22 '11 at 21:22
  • yep.!! thanks. will continue posting my updates here :) – Lalith Jul 22 '11 at 23:30
  • Button is fine.. Now I am trying out text field.. but looks like i cannot fire up UIControlEventEditingDidBegin doesn't exactly work. It wasn't firing up textfield selection nor keyboard pops up. – Lalith Jul 23 '11 at 00:03
  • 1
    What do you think about edit2? – Rui Peres Jul 23 '11 at 00:08
  • man you are awesome! Dunno how it worked but any explanation helps.. i could google it though. – Lalith Jul 23 '11 at 00:14
  • @JackyBoy let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/1753/discussion-between-lalith-and-jacky-boy) – Lalith Jul 23 '11 at 00:15
4

Apple has a framework for javascript-based automation via instruments and the accessibility APIs. It's not 100% awesome the best, but it's worth taking a look.

Instruments + actually touching the phone with your finger is a pretty good way to do performance analysis "in the real world" as well.

Generally, I haven't found it worthwhile to automate UI testing. The UI generally changes too much to make a functional spec less work than it's worth. YMMV.

Andrew Pouliot
  • 5,423
  • 1
  • 30
  • 34
4

Once you get to a point you are comfortable, I would look at this KIF framework.

KIF, which stands for Keep It Functional, is an iOS integration test framework. It allows for easy automation of iOS apps by leveraging the accessibility attributes that the OS makes available for those with visual disabilities.

Scott Densmore
  • 1,459
  • 10
  • 10
2

You could create a parent UIView, to which you add "children" or subviews. The subviews contain your application UI.

The parent view is set up to be transparent, and it captures touches and logs them. Once logged, the touch event is passed down to the subviews. You could send your test touches here.

Because the parent view is transparent, the user never sees it, but it still captures and processes touch events.

Setting this up would involve a fair amount of subclassing, and some classes (such as UIWebView) introduce difficulties. But it might be feasible.

Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
0

I've been using IMAT quite successfully for iOS automation.

https://code.intuit.com/sf/sfmain/do/viewProject/projects.ginsu

Reasons I like it:

  1. It's built right on top of the javascript automation that Apple provides and you can kick it off from Instruments or command line
  2. It provides a test-runner (think N-Unit) for javascript iOS automation
  3. Provides a neat mechanism for retrieving UI Elements (similar to an object map used by other automation tools)
  4. Requires no changes to your app code (no need to build with a certain library or instrument your code)
  5. Provides a jUnit like report after a test run by reading the plist file and this is picked up by my CI Tool (Teamcity, Jenkins, CruiseControl)
sogwiz
  • 486
  • 3
  • 14
0

Thanks for all your help. As I have mentioned in a comment that I should be able to run them in IOS device as stand alone. We can use sendActionsForControlEvents as described here . This is all I need for now.

Community
  • 1
  • 1
Lalith
  • 19,396
  • 17
  • 44
  • 54
0

You can consider SeeTest from Experitest, it comes with very easy record and replay capabilities.

Guy
  • 325
  • 2
  • 6
  • 14