我正在创建 Automate UITest 测试用例,我想在其中测试用户与元素进行 3D Touch 交互的场景,然后向他们显示 Peek 和 Pop View 。
我似乎找不到任何可能的方法来模拟元素上的 3D Touch 并继续。
有人对此有任何想法吗,或者 3D Touch 仍然无法测试?
谢谢
最佳答案
我能够在运行 iOS 10.3 的 iPhone 7 上的应用程序图标上执行强制按下/3D Touch。这在 10.2 上是不可能的。
objective-C
首先您必须声明以下内容或导入 this header
typedef void (^CDUnknownBlockType)(void);
@interface XCEventGenerator : NSObject
+ (id)sharedGenerator;
// iOS 10.3 specific
- (double)forcePressAtPoint:(struct CGPoint)arg1 orientation:(long long)arg2 handler:(CDUnknownBlockType)arg3;
@end
然后执行强制按下
XCUIElement *element = ...; // Get your element
XCUICoordinate *coord = [mapsIcon coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.5)];
[[XCEventGenerator sharedGenerator] forcePressAtPoint:coord.screenPoint orientation:0 handler:^{}]; // handler cannot be nil
在这里,我用力按下 map 图标。
Swift(未测试)
对于 Swift,你必须声明/导入与上面相同的接口(interface)/ header ,然后像这样执行强制按下
let el = ...; // Get your element
let coord = el.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5) )
let eventGenerator: XCEventGenerator = XCEventGenerator.sharedGenerator() as! XCEventGenerator
eventGenerator.forcePress(at: coord.screenPoint, orientation: 0) { }
关于ios - 让 XCUIElement 为自动化 UITest 执行 3D 触摸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39284082/