I've been giving a try to the new UI tests on XCode 7.3 and I've found what it seems a bug to me.
The problem is that views added through the "addSubview" method seems to be completely invisibles to the UI test system.
I have this view:
And this UIview creating code:
let container = UIView(frame: CGRectMake(0, 0, 375, 200))
container.backgroundColor = UIColor.orangeColor()
container.isAccessibilityElement = false
let label = UILabel(frame: CGRectMake(0, 100, 375, 20))
label.backgroundColor = UIColor.yellowColor()
label.textAlignment = NSTextAlignment.Center
label.accessibilityIdentifier = "labelIdentifier"
label.text = "I am a label"
container.addSubview(label)
And this simple UI test:
func testExample() {
let final = XCUIApplication().staticTexts.containingType(.StaticText, identifier: "labelIdentifier").element
XCTAssertEqual(final.label, "I am a label")
}
The problem is that, depending on how I attach the orange view, the test doesn't find the label. If I do a:
self.tableView.tableHeaderView = container
Test pass without any problem at all but attaching it with:
self.tableView.addSubview(container)
Probokes the next error:
After digging a little in the forums I've already tested all recommended settings like setting to false the container "isAccessibilityElement" property and such, but nothing seems to work.
Long story made short. ¿Anyone have tried to get an element attached to other UIView with the add "addSubview" method?
Hello I craete a sample project with tableView and your container
and add container to tableView
Try this example :)
Have you trying Xcode recording to get that view ? Just record and press on your view it should works
Also make sure that this UILabel is not outbounds "you can inspect using Xcode"