I am writing XCUITests for my app in Swift, and I was wondering if it's possible to simulate the locking and unlocking of a device. I've looked at XCUIApplication
methods but there don't seem to be any that allow me to lock the device.
Asked
Active
Viewed 1,358 times
4

Senseful
- 86,719
- 67
- 308
- 465

SalmonKiller
- 2,183
- 4
- 27
- 56
3 Answers
2
According to this answer, there's a private method on XCUIDevice that you can call to lock the screen as follows:
XCUIDevice.shared.perform(NSSelectorFromString("pressLockButton"))

Essam Ewaisha
- 439
- 5
- 15
1
I'm not sure but may be it is possible to do via some magic sentence like:
let siri = XCUIDevice().XCUISiriService // available since SDK 10.3
siri.activate(voiceRecognitionText: "siri, please lock my device")

Maxim Kholyavkin
- 4,463
- 2
- 37
- 82