skip to Main Content

My app has a feature that allows me to open system settings (Preferences app).
The system Back button appears in such cases, with a left arrow and the original app name.

I mean this one:

enter image description here

So, my question is: how can I tap this button in XCUITests?
I tried to use Springboard app:

let app = XCUIApplication(bundleIdentifier: "com.apple.springboard")
let button = app.buttons["my-app"]
if button.exists {
    button.tap()
}

And Preferences app:

let app = XCUIApplication(bundleIdentifier: "com.apple.Preferences")
let button = app.buttons["my-app"]
if button.exists {
    button.tap()
}

But there was no result.
What app shows the button? With what identifier can I find the button?

2

Answers


  1. Rather than working with the system UI, which has a tendency to change out from under you and break tests, I’d suggest simply calling activate() on your app, which should bring it to the foreground.

    If you really feel the need to use that back button, just know you’re testing the OS, not your application.

    Login or Signup to reply.
  2. I agree with Mike Collins’ response. However, if you’re specifically looking for how to press that button, here’s how you can do it:

    XCUIApplication(bundleIdentifier: "com.apple.springboard").statusBars.buttons["breadcrumb"].tap()
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search