Question

I need to know if there is any way to close app if it is open in UIAutomation. I would like to share some code but i simply cannot find anything about it.

Thanks in advance.

Was it helpful?

Solution

If you are using Tune_up.js(cmdline) to run your UIA tests at the end of each test function the app will reset its state.

Other than this the only things you can do to simulate closing the app would be to deactivate the app which sends it to the background for a given amount of time and then returns it to the foreground.

Additionally you could simulate locking the device, however I have never tried this specifically.

target.deactivateAppForDuration() https://developer.apple.com/library/ios/documentation/ToolsLanguages/Reference/UIATargetClassReference/UIATargetClass/UIATargetClass.html#//apple_ref/javascript/instm/UIATarget/deactivateAppForDuration

OTHER TIPS

iOS applications cannot be quitted normally. UI Automation does only actions that can be performed by the user and because the user cannot quit the app, UI Automation cannot quit the app.

Also note that quitting the application would interrupt your Automation script.

Maybe you could split the test case into 2 scripts and run them sequentially?

We had this problem as well. You can write an simple Apple script to click the Home button of the simulator which would close the Application. I am sure you would be able to find the apple script to click the home button of the simulator.

Or even better, see below :p... Just made ur task easier..
tell application "System Events" tell process "iPhone Simulator"
tell menu bar 1
tell menu bar item "Hardware"
tell menu "Hardware"
click menu item "Home"
end tell
end tell
end tell
end tell
end tell

Hope this helps.

The problem would be how to open the closed app/ once you put the app to the background? Let me know if you find an answer to that

If you just want to close the app as in put it in the background then use the deactivateAppForDuration() method at the end of your tests.

If you really want to kill the app and the simulator, it's actually pretty simple. Just create a shell script in which you run your tests through the command line and then once it's done pass the killall "iPhone Simulator" command.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top