Modeling Home Button Presses - iPhone Testing

So, I am working on testing an application for the iPhone. I am trying to install test cases that we can use later using UIAutomation (I am not attached to this - I can switch to another structure). I basically need to create a test that looks something like this:

+ 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 know how to do this or what infrastructure to use for this?

Thanks in advance.

+4
source share
4 answers

You cannot simulate a press of the home button, but you can force the application to exit as if it were. Call [[UIApplication sharedApplication] terminate]; will end or (in the case of iOS 4.x) the background of the application. However, you cannot restart the application using UIAutomation.

You can try UIAutomation in conjunction with an on-screen recording script that allows you to play back mouse movements and clicks. This will allow you to interact directly with the simulator for things such as clicks on the home button and clicks on application icons.

Alternatively, you can get "fairly good" testing using the UIATarget class. In documents

The UIATarget class represents the high-level user interface of the system under test (SUT), that is, your application, iOS, and the connected device on which they work. Your test scripts, written in JavaScript and working in conjunction with the Automation Tool user interface, use this class and its UIA classes to execute SUT and log results.

Using UIATarget.localTarget().deactivateAppForDuration(seconds); , you can create your application in a few seconds.

Use this method to check the porting of the application to and from the background execution context. Please note that applications created using iOS SDK 4.0 or later and work in iOS 4.0 and later if the user clicks the Home button. See the iOS App Programming Guide for details on multitasking and background execution context.

+7
source

You can click the home button in Xcode 7 by testing the user interface.

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

Source: fooobar.com/questions/1366414 / ...

+3
source

I do not think it is possible, but you can use

 UIATarget.localTarget().deactivateAppForDuration(100); 

To place your application in the background for a certain time.

+1
source

device button click 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
source

All Articles