skip to Main Content

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


  1. 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 XCUIElements that live within your own application window.


    Credits*Applies to XCTest

    Login or Signup to reply.
  2. It’s now accessible as a springboard descendant:

    class Springboard {
    
        static let shared = XCUIApplication(bundleIdentifier: "com.apple.springboard")
    
        static var statusBar: XCUIElement {
            // There are always two statusBars, 
            // but only one of them is accessible when we need to tap it
            if XCUIDevice.shared.orientation.isPortrait {
                return Springboard.shared.statusBars.firstMatch
            }
            else {
                return Springboard.shared.statusBars.element(boundBy: 1)
            }
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search