XCUITest still sees SFSafariViewController after it's been dismissed

Got a situation where our UI tests are failing because according to print(app.debugDescription) the XCUITests still "see" an SFSafariViewController even though it's been dismissed (and appears to be dismissed on the device.)


To illustrate:


print(app.debugDescription)

let result = app.navigationBars.staticTexts["My Title"].firstMatch.waitForExistence(timeout: 30)

print("Did I find it?")

print(result)

print("Maybe, see above")


In the above code, the first app.debugDescription prints an accessibility tree describing the SFSafariViewController. The print(result) statement prints "false" and breakpointing on the line after that and running po app.debugDescription shows me the same tree. Though it's obvious from the device display that the SFSafariViewController has been dismissed.


Anyone else seeing this problem? I'd like to know if it's a Known Bug before I go to the effort of swapping out SFSafariViewController for SFAuthenticationSession.

Accepted Reply

For future reference; the above *used* to work in Xcode 8/iOS 10, now we've found this works in Xcode 9/iOS 11:


func testExample() { 
    let result = app.naviagationBars["My Favourites"].firstMatch.waitForExistence(timeout: 10) 
    XCTAssert(result) 
}


Spot the difference*!


(* "staticTexts" is no longer allowed. I've updated the radar, I don't know if this counts as a regression or not.)

Replies

Radar'd as 34708605


(Also see rdar://34708531 in which XCUITest craps out with an assertion error on an SFSafariViewController before even getting to the point of dismissing it.)

Well, I've just knocked up a fresh, simple project and it seems that asserting the text of a title in a nav bar simply doesn't work. Vis, this:


    func testExample() {
        let result = app.navigationBars.staticTexts["My Favourites"].firstMatch.waitForExistence(timeout: 10)
        XCTAssert(result)
    }


... fails. wat? Has anybody else seen this behaviour? Am I doing something boneheaded?

For future reference; the above *used* to work in Xcode 8/iOS 10, now we've found this works in Xcode 9/iOS 11:


func testExample() { 
    let result = app.naviagationBars["My Favourites"].firstMatch.waitForExistence(timeout: 10) 
    XCTAssert(result) 
}


Spot the difference*!


(* "staticTexts" is no longer allowed. I've updated the radar, I don't know if this counts as a regression or not.)