Swift UI Test Find Custom UIView XCUIElement
Asked Answered
S

1

7

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

I've tried hitting 'record' and selecting it, but it does not seem to be selectable, as it does not write the code to find it when I tap it.

I've tried locating it programmatically, but XCUIElementType Any and Other don't seem to be finding it and I don't see a more appropriate one for View.

I've tried setting accessibility in the storyboard, but all accessibility seems to vanish upon running the unit test.

This seems like it should be pretty basic, so sorry if I have missed something here.

Scopoline answered 27/8, 2015 at 15:36 Comment(4)
Are you using the latest Xcode? Beta 6 I think... If you share your code I could take a look.Fluctuation
Wow they release a new version of this beta every week it seems, no I'm on 5. I don't really have much code to share since I don't know how to do it; The ideal code would look soemthing like self.app.xxx.elementBoundByIndex(UInt(0)) where xxx is views, similar to how one would access the other elementsScopoline
Did you find a solution to that?Diatomaceous
@Diatomaceous I still haven't found a way to do itScopoline
P
-1

As far as I understand, XCUI uses accessibility information to access object. In my app, I have a custom view that semantically behaves like an image (it shows some graphic content). It is setup using interface builder, so in the storyboard, I selected it and turned on the following accessibility elements.

snapshot of interface builder

Other elements of my apps are custom UIView that acts like button, and are bundled inside another custom uiview, so I can't set their accessibility properties from interface builder. So I set them in code:

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

with that, recording mode finds all my custom views very nicely.

Panettone answered 3/12, 2016 at 13:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.