๐Ÿ”ซ Hit-testing in Waldo

FAQs regarding the use of hit-testing in Waldo tests.

What is hit-testing?

When iOS processes a touch event (for example, a tap or swipe), it walks the view hierarchy to find the closest UI element that will accept the event. If the first UI element tested wonโ€™t accept the event, iOS checks the next closest UI element, and so on. This process is called hit-testing.

The UIView class provides two methods to accomplish this:

-[UIView hitTest:withEvent:]
 -[UIView pointInside:withEvent:]

The UIView.hitTest(_:with:) method traverses the view hierarchy by calling the UIView.point(inside:with:) method of each subview to determine which subview should receive a touch event.

If UIView.point(inside:with:) returns true (or YES), then the subviewโ€™s hierarchy is similarly traversed until the frontmost view containing the specified point is found. If a view does not contain the point, its branch of the view hierarchy is ignored.

The UIView.point(inside:with:) method simply returns a Boolean value indicating whether the view contains the specified point.

How does Waldo use hit-testing?

Whether you are recording or replaying a test flow, or interacting with Waldo Live, Waldo continually analyzes the current view hierarchy of your app. To resolve ambiguities in the view hierarchy, Waldo employs hit-testing. In the vast majority of cases, Waldo is able to correctly analyze the view hierarchy.


Be Aware:

In rare cases, this analysis fails because the app overrides a hit-testing method in a problematic way.

How does overriding a hit-testing method cause problems for Waldo?

In a nutshell, overriding a hit-testing method may cause a problem for Waldo if it initiates any action that changes the view hierarchy.

For example: we have seen numerous cases where an override dismisses an overlay view (or even the target view itself). We have also seen cases where an app uses a 3rd-party library that includes a problematic override of a hit-testing method.

When can overriding a hit-testing method be used successfully with Waldo?

In general, an override that simply resizes the hit area, or that excludes a region of the hit area, will not be problematic for Waldo.


Example of a successful override

A common example is overriding the hit-testing method for a small button in order to increase its hit area to be in compliance with the minimum size suggested by Appleโ€™s Human Interface Guidelines.