7

I have an app. There is a button in the app, which, if clicked, exits the app. I am testing the app using UIAutomation instruments. I want to test this button. But after the app exits, the instrument stops giving an exception. What I want to do is that after the app exists, I want to reopen the app and continue with the rest of the test. Have anyone else been in the same scenario? If so, can you please share the solution, if you have found any?

  • Just FYI - Apple does not like it when you have a button that exists the app. Are you building for the app store? – nycynik May 04 '12 at 18:33
  • Yeah, its already on the appstore. Its a messenger and there is this button that resets the app.(it deletes the log in info) As a consequence, the app exits. So technically it is not a button to exit the app. – Farhan Ahmed Wasim May 04 '12 at 18:40

3 Answers3

3

This is not possible because Instruments loses the connection with the app process once it quits.

If you are scripting UI Automation from the command line, you can run a second automation script after the first one quits the app that then checks to make sure everything is reset.

instruments \
    -D [trace document] \
    -t [instruments template] \
    /path/to/Bundle.app \
    -e UIARESULTSPATH [directory to store test output] \
    -e UIASCRIPT reset_the_app.js

instruments \
    -D [trace document] \
    -t [instruments template] \
    /path/to/Bundle.app \
    -e UIARESULTSPATH [directory to store test output] \
    -e UIASCRIPT check_that_the_app_is_reset.js

So, rather than trying to get the same instance of Instruments to relaunch and reattach to the app, just run two separate scripts, one that does your reset-and-abort, and the other that checks the resulting state of the app.

Jonathan Penn
  • 1,341
  • 7
  • 8
0

You can Use:

UIATarget.localTarget().deactivateAppForDuration(n); 

where n is the number of seconds you want this app to restart. I hope this helps.

DisplayName
  • 3,093
  • 5
  • 35
  • 42
  • Deactivating the app is not not in any way a restart. See doc like https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StrategiesforHandlingAppStateTransitions/StrategiesforHandlingAppStateTransitions.html#//apple_ref/doc/uid/TP40007072-CH8-SW1 for more information. – James Moore Nov 19 '14 at 17:24
0

thanks for the answers, but the documentation says:

"When a user exits your app by tapping the Home button or causing some other app to come to the foreground, your app is suspended."

So its not restarting but suspended?

daniel.lozynski
  • 14,907
  • 6
  • 18
  • 21