XCTest - UI Testing with XCUIElement using pinch gesture on custom coordinates?

孤街浪徒 提交于 2021-01-28 11:28:35

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/65635857/xctest-ui-testing-with-xcuielement-using-pinch-gesture-on-custom-coordinates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!