Swift UI Test Find a Custom UIView XCUIElement

I want to find a UIView XCUIElement, but I cannot find it. This UIView is used to display certain information to the user, and I need to be able to check if it is on the screen in certain situations. I have view.userInteractionEnabled set to YES.

I tried to press the β€œrecord” and select it, but it seems that it cannot be selected, since it does not write code to find it when I click it.

I tried to find it programmatically, but XCUIElementType Any and Other does not seem to find it, and I do not see a more suitable View.

I tried to set the accessibility in the storyboard, but all the availability seems to disappear when the unit test runs.

It seems to be pretty simple, so sorry if I missed something.

+7
swift swift2 coded-ui-tests
source share
1 answer

As I understand it, XCUI uses the available information to access the object. In my application, I have a custom view that semantically behaves like an image (it displays some graphic content). It is configured using the interface designer, so in the storyboard I selected it and included the following accessibility elements.

interface builder snapshot

Other elements of my applications are the custom UIView, which acts like a button and enters another user uiview, so I cannot set their accessibility properties from the interface constructor. So I installed them in the code:

self.accessibilityTraits = UIAccessibilityTraitButton self.accessibilityIdentifier = "commit" self.accessibilityLabel = "Commit" 

with this, the recording mode finds all my user views very nicely.

0
source share

All Articles