我正在创建自动化 UI 测试测试用例,我想测试用户与元素进行 3D Touch 交互时的场景,然后向他们显示 Peek 和 Pop 视图。
我似乎找不到任何可能的方法来在元素上模拟 3D Touch 并继续。
有人对此有任何想法吗?或者 3D Touch 仍然无法测试?
Thanks
我能够在运行 iOS 10.3 的 iPhone 7 上的应用程序图标上执行强制按压/3D Touch。在 10.2 上这是不可能的。
Objective-C
首先您必须声明以下内容或导入这个标题
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
在这里,我对地图图标执行了强制按压。
斯威夫特(未测试)
对于 Swift,你必须声明/导入与上面相同的接口/标头,然后像这样执行强制按下
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) { }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)