lan*_*rey 2 ios xcode-ui-testing
如何使用 UITests 触摸特定坐标?
当我在特定位置录制点击时,我有类似的东西:
XCUIApplication *app = [[XCUIApplication alloc] init];
[[[[[[[[[[app.otherElements containingType:XCUIElementTypeNavigationBar
identifier:@"Navigation Bar title"]
childrenMatchingType:XCUIElementTypeOther].element
childrenMatchingType:XCUIElementTypeOther].element
childrenMatchingType:XCUIElementTypeOther].element
childrenMatchingType:XCUIElementTypeOther] elementBoundByIndex:0]
childrenMatchingType:XCUIElementTypeOther].element
childrenMatchingType:XCUIElementTypeOther]
elementBoundByIndex:0].staticTexts[@"Action"] tap];
Run Code Online (Sandbox Code Playgroud)
您只能点击以已知元素为参考的特定坐标。意思是,您不能点击坐标 (20, 400) 处的像素。相反,您需要找到一个元素,然后点击具有偏移量的元素。
XCUIApplication *app = [[XCUIApplication alloc] init];
XCUIElement *label = app.labels[@"Label Name"];
XCUICoordinate *coordinate = [label coordinateWithNormalizedOffset(CGVectorMake(0.5, 1.2));
[coordinate tap];
Run Code Online (Sandbox Code Playgroud)
我在我的UI 测试备忘单帖子中记录了有关如何确定正确偏移量的更多信息。
如果您只是想点击Action按钮,您可以直接访问它(而不是深入了解所有这些查询)。
XCUIApplication *app = [[XCUIApplication alloc] init];
[[[app.navigationBars element].staticTexts[@"Action"] tap];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3035 次 |
| 最近记录: |