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
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
Swift 4 :
XCUIDevice.shared.press(.home)
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);
[[UIApplication sharedApplication] terminate];
UIATarget.localTarget().deactivateAppForDuration(seconds);
(apologies for using objc)
Goal c
[XCUIDevice.sharedDevice pressButton:1];
Home button = 1, volume up button = 2, volume down button = 3.
In Swift version 4.0.2 and 4.0.3 :
XCUIDevice.shared().press(XCUIDeviceButton.home)
Now in Swift 4.1 :
XCUIDevice.shared.press(XCUIDevice.Button.home)