UI Testing can't find button in tableView.backgroundView

Our UI test can't find a button which is a subview of a UITableView backgroundView (the button is laid out in the Storyboard as an assoicated view on the UITableViewController's scene and set as the tableView.backgroundView in viewWillAppear().)


When we run the app we can tap the button fine.


Using the Live View Debugger we can see that there is a UITableViewWrapperView on top of the backgroundView, and we were wondering if this is interfering with UI Testing.


Has anyone been able to make this work?

(The button is a custom @IBDesignable UIButton subclass, if that matters.)

I don't know anything about UI testing, but putting a button in the background view sounds like trouble. I wouldn't be surprised at all if that suddenly stopped receiving touches in some future iOS version.

Really? Can you point to some documentation that indicates this is a bad idea?


(For those wondering, we've managed to work around it by tapping at a .coordinateWithNormalizedOffset() from a label UI Testing can find.)

No that comment is just based on experience and gut feel. I don't know of any documentation other than the name of the property "backgroundView". A background is something that is intended to be covered up. Apple tends to be pretty careful with naming things for their intended purpose. If it happens to work when used some other way that's just a coincidence and shouldn't be relied upon, IMO.


People have been burned doing things like that in the past (adding subviews to UIAlertView comes to mind). It may be fine and continue to work forever, or it may not. 🙂

it's the same problem for me. Did you find any solution?

No, nothing aside from the withNormalizedOffset trick alluded to above. Dupe rdar://25650889 (it has a sample project attached.)

UI Testing can't find button in tableView.backgroundView
 
 
Q