如何使用Xcode UITests点击特定点 [英] How to tap on a specific point using Xcode UITests

查看:510
本文介绍了如何使用Xcode UITests点击特定点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Fastline Snapshot 中使用Xcode UI测试来制作屏幕截图科尔多瓦应用程序。基本上,由于我的整个应用程序只是一个Web视图,所有xcode UI测试助手方法变得无关紧要,我只想点击特定点,例如点击(x:10,y:10)应该点 {10px; 10px}

I want to use Xcode UI tests with the Fastline Snapshot to make screenshots of the Cordova app. Basically, as my entire app is just a web view, all the xcode UI test helper methods become irrelevant, and I just want to tap on specific points, e.g. tap(x: 10, y: 10) should produce a tap at the point {10px; 10px}.

这可能非常简单,但我无法弄明白该怎么做。

That's probably very simple, but I can't figure out how to do it.

谢谢。

推荐答案

您可以使用 XCUICoordinate API 。不幸的是,您不能只是说点击10,10引用像素坐标。您需要创建具有实际视图的相对偏移的坐标。

You can tap a specific point with the XCUICoordinate API. Unfortunately you can't just say "tap 10,10" referencing a pixel coordinate. You will need to create the coordinate with a relative offset to an actual view.

我们可以使用提到的Web视图与相对坐标进行交互。

We can use the mentioned web view to interact with the relative coordinate.

let app = XCUIApplication()
let webView = app.webViews.element
let coordinate = webView.coordinateWithNormalizedOffset(CGVector(dx: 10, dy: 10))
coordinate.tap()






旁注,但您是否尝试直接与网络视图进行交互?我使用 app.links [链接标题]取得了很大成功.tw() app.staticTexts [一个不同的链接标题]。轻触()这是一个演示应用程序,我放在一起演示与a网页视图。

更新:正如Michal W.在注释,您现在可以直接点击坐标 ,而无需担心规范化偏移。

Update: As Michal W. pointed out in the comments, you can now tap a coordinate directly, without worrying about normalizing the offset.

let normalized = webView.coordinateWithNormalizedOffset(CGVector(dx: 0, dy: 0))
let coordinate = normalized.coordinateWithOffset(CGVector(dx: 10, dy: 10))
coordinate.tap()

请注意,我将0,0传递给标准化向量,然后将实际点10,10传递给第二个打电话。

Notice that I pass 0,0 to the normalized vector and then the actual point, 10,10, to the second call.

这篇关于如何使用Xcode UITests点击特定点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆