开发者

Simulating a Home Button Press - iPhone Testing

So I'm working on testing an iPhone app. I'm trying to setup test cases that we can use later using UIAutomation (I'm not really tied down to this - I can switch to some other framework). I basically need to create a test that goes something like:

+ Launches application
+ Clicks a few specific buttons
+ Hits the home button exiting the application
+ Relaunches the application
+ Checks the status of the application

Does anyone have any idea how to do this or wh开发者_如何学JAVAat framework to use to do this?

Thanks in advance.


You can't simulate the home button being pressed, but you can force the app to exit as if it were. Calling [[UIApplication sharedApplication] terminate]; will terminate or (in the case of iOS 4.x) background the app. You will not, however, be able to relaunch the application using UIAutomation.

You could try UIAutomation in combination with a screen recording script that allows you to replay mouse movement and clicks. This would allow you to interact with the simulator directly for things like home button clicks and app icon clicks.

Alternately you can get "good enough" testing using the UIATarget class. Per the docs,

The UIATarget class represents high-level user interface elements of the system under test (SUT)—that is, your application, the iOS, and the connected device on which they’re running. Your test scripts, written in JavaScript and running in conjunction with the UI Automation instrument, use this class and related UIA classes to exercise the SUT and log results.

Using UIATarget.localTarget().deactivateAppForDuration(seconds); you can background your app for n seconds.

Use this method to test shifting your application to and from the background execution context. Note that applications built using iOS SDK 4.0 or later and running in iOS 4.0 and later aren’t necessarily terminated when the user presses the Home button. See iOS Application Programming Guide for details of multitasking and background execution context.


It is possible to press the home button in Xcode 7 with UI Testing.

XCUIDevice.sharedDevice().pressButton(XCUIDeviceButton.Home)

Source: https://stackoverflow.com/a/33087217/142358


I don't think this is possible but you could use

UIATarget.localTarget().deactivateAppForDuration(100);

To put your app in the background for a specific amount time.


presses device home button in iOS

def hit_home
  home =`osascript -e 'tell application "System Events" to tell process "iOS Simulator"' -e'keystroke "H" using command down' -e'delay 2' -e'end tell'`
  puts("home button exits - #{home.to_i}")
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜