I am trying to create a XCUITest where I like to verify that iOS’ Status Bar is either:
- hidden; or
- visible.
But I cannot ‘find’ it… for example:
func testExample() throws {
let app = XCUIApplication()
app.launch()
let statusBar1 = app.descendants(matching: .statusBar)
let statusBar2 = app.statusBars.element(boundBy: 0)
}
When do po statusBar1
in the console I get an empty result:
Find: Target Application 'com.domain.TestStatusBar'
↪︎Find: Descendants matching type StatusBar
Any clue of how to find it?
Thanks!
2
Answers
As of iOS 12, the status bar is no longer accessible through
XCTest
as it is a part of the system application.If you check in iOS 11 & below,
app.descendants(matching: .statusBar).element
should have the expected result.In other words, you can access only those
XCUIElement
s that live within your own application window.Credits*Applies to
XCTest
It’s now accessible as a springboard descendant: