简体   繁体   中英

XCUITest - How to simulate locking of the device

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.

目前这是不可能的。

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")

根据这个答案,在XCUIDevice上有一个私有方法,您可以调用以锁定屏幕,如下所示:

XCUIDevice.shared.perform(NSSelectorFromString("pressLockButton"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM