Simulation Pressing the Home Button in xCode 7 Automating the User Interface

I have it:

XCUIDevice.pressButton(noideawhatgoeshere) 

I tried XCUIDeviceButtonHome, home, Home, 1

Not sure how to simulate a home button press, does anyone have any pointers? I'm new to xCode / swift

+4
source share
6 answers

First you need to get an instance of the device. So, to simulate pressing the home button:

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

should work (this is done for me on a physical device)

Thanks!

Mazen

+11
source

Swift 4 :

 XCUIDevice.shared.press(.home) 
+4
source

I do not know how to simulate a home button - it may be impossible. You can sort it using: [[UIApplication sharedApplication] terminate]; or you can put your application in the background for a certain duration with: UIATarget.localTarget().deactivateAppForDuration(seconds);

(apologies for using objc)

+2
source

Goal c

  [XCUIDevice.sharedDevice pressButton:1]; 

Home button = 1, volume up button = 2, volume down button = 3.

+2
source

In Swift version 4.0.2 and 4.0.3 :

 XCUIDevice.shared().press(XCUIDeviceButton.home) 
+2
source

Now in Swift 4.1 :

 XCUIDevice.shared.press(XCUIDevice.Button.home) 
0
source

All Articles