XCTest - 在自定义坐标上使用捏合手势使用 XCUIElement 进行 UI 测试? [英] XCTest - UI Testing with XCUIElement using pinch gesture on custom coordinates?

查看:54
本文介绍了XCTest - 在自定义坐标上使用捏合手势使用 XCUIElement 进行 UI 测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个应用,其 UI 看起来有点像下图:

假设蓝色视图的行为类似于地图,而其他颜色是其他可交互的视图.

我需要在需要缩小"的地方进行 XCTest在我厌倦了

在该空视图上执行 pinchWithScale 工作并实际捏住 blueView.

这是一个非常丑陋的解决方案,因为我必须添加一个仅用于 UI 测试的视图.

如果有人有关于如何为发布版本删除它的提示,请告诉我.

更新

我执行了一个运行脚本的构建步骤,该脚本仅在执行 UI 自动化测试目标时添加此视图.执行后使用源代码控制撤销添加的视图.

Let's say I've an app with an UI which looks kind of like the image below:

Let's also say the blue view behaves like a map and the other colors are other interactable views.

I need to do a XCTest where I need to "zoom out" on that blue view which I tired with pinchWithScale:

[blueView pinchWithScale:0.5 velocity:-1];

Unfortunately that doesn't work because one of the red views or the violet view (which overlaps the blue view a tiny bit for shadow and corner reasons) gets triggered instead of a pinch gesture on the blue view.

I saw that I can get coordinateWithNormalizedOffset (similar like here) of a view by using the method:

- (XCUICoordinate *)coordinateWithNormalizedOffset:(CGVector)normalizedOffset;

which would allow me to use not the whole blue view to perform a "zoom out" gesture by:

XCUICoordinate* blueViewInset = [blueView coordinateWithNormalizedOffset:
                                 CGVectorMake(0.2f, 0.2f)];

but the XCUICoordinate object blueViewInset doesn't support pinch gestures.

Hence how can I perform a pinch gesture to "zoom out" on a XCUIElement with coordinates not at the border of the view?

I'm also wondering if there is a way to create an extension to XCUIElement with a custom pinch gesture? I would appreciate any hints on that too.

解决方案

I figured out that I can (but don't want to) add another empty view on top of my blueView with constraints to half of the size of it. This works for all my cases so far because no other view overlaps that far. It looks something like this:

Executing a pinchWithScale on that empty view works and actually pinches the blueView.

This is a very ugly solution, since I've to add a view which is solely for UI testing.

If anyone has a hint on how to remove it for the release build let me know.

Update

I made a build step running a script which adds this view only when executing the UI automation test target. After the execution the source control is used to undo the added view.

这篇关于XCTest - 在自定义坐标上使用捏合手势使用 XCUIElement 进行 UI 测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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