skip to Main Content

I need to check if an app with a particular bundleIdentifier is installed on the active device or Simulator and I need to do this from an XC UI test.

I’ve tried doing:

import XCTest

class ServerLoop: XCTestCase {
  func testRunAppInstalled() async throws {
    let app = XCUIApplication("pl.bartekpacia.SomeApp")
    if app.exists {
      // code
    }
  }
}

but unfortunately it only tells me if the app is currently open, not installed.

I want to be able to check if any app is installed, not only my apps. I need this because if the app with bundleId is not installed and I do XCUIApplication(bundleId), then the test fails and there’s no way to prevent it from doing so.

2

Answers


  1. I couldn’t make it work with the bundle identifier. But if you have the name of the app as it is visible on springboard, this code works in my tests:

    func test_existence() {
        let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
        let appIcon = springboard.icons["Settings"]
        if appIcon.exists {
            print("YEAH!")
        } else {
            XCTFail()
        }
    }
    
    Login or Signup to reply.
  2. It seems like the SpringBoard solution is a good one.

    You could also attempt a launch of an XCUIApplication and expect a fail on the test with XCTExpectFailure in nonStrict mode, with the continueAfterFailure property on XCTestCase set to true.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search