mercredi 22 juin 2016

Xcode UI testing - Uiviews added with addSubview are completely invisible to the UI tests

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:

enter image description here

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:

enter image description here

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?

Aucun commentaire:

Enregistrer un commentaire