ios – 让XCUIElement为Automate UITest执行3D触控?

我正在创建Automate UITest测试用例,我想在用户与元素进行3D Touch交互时测试场景,然后显示Peek和Pop视图.

我似乎找不到任何可能的方法来模拟元素上的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

在这里,我在地图图标上执行强制按下.

斯威夫特(未经测试)

对于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) { }

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...