让XCUIElement为Automate UITest执行3D触摸?

AGP*_*ich 10 ios swift xcode-ui-testing 3dtouch

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

我似乎找不到任何可能的方法来模拟元素上的3D Touch并继续.

任何人对此有任何想法,或3D Touch仍无法测试?

谢谢

Tit*_*eul 5

我能够在运行 iOS 10.3 的 iPhone 7 上的应用程序图标上执行强制按压/3D Touch。在 10.2 上是不可能的。

目标-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
Run Code Online (Sandbox Code Playgroud)

然后执行强制按下

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
Run Code Online (Sandbox Code Playgroud)

在这里,我对地图图标执行强制按下。

斯威夫特(未测试)

对于 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) { }
Run Code Online (Sandbox Code Playgroud)