Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulating pressing the Home button in Xcode 7 UI Automation

I've got it down to:

XCUIDevice.pressButton(noideawhatgoeshere)

I've tried XCUIDeviceButtonHome, home, Home, 1

How do I simulate pressing the home button in Xcode on iOS?

like image 813
cakes88 Avatar asked Sep 29 '15 21:09

cakes88


People also ask

What is UI testing Xcode?

UI testing allows you to automate this procedure, so every time you update your code, Xcode will automatically test whether your app works correctly without you having to manually do it.


2 Answers

You need to get the device instance first. So to simulate pressing the home button:

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

should work (it does for me on a physical device)

Thanks!

Mazen

Swift 5 Version:

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

Also, verified it works in the simulator, at least in Xcode 11.2.1 on a simulated "iPad Pro (9.7-inch)" running iPadOS 13.2.2.

like image 101
Mazen A Avatar answered Nov 09 '22 23:11

Mazen A


Swift 4:

XCUIDevice.shared.press(.home)
like image 40
ScottyBlades Avatar answered Nov 10 '22 00:11

ScottyBlades