Is it possible to do iOS XCUITesting on multiple simulator devices simultaneously?

Viewed 1463

I have an app which in production will be on five different devices, talking to each other using MultipeerConnectivity. I have a bash script which launches the app on five different Simulators. This works great, but there are many buttons I have to tap on each device to test everything each time.

So I thought maybe XCUITest could help to automate this, and remove these external bash script dependencies (would like to do everything within Xcode/Swift). I tried a naive approach like this:

func testExample() {
    // Use recording to get started writing UI tests.
    // Use XCTAssert and related functions to verify your tests produce the correct results.

  let app1 = XCUIApplication(bundleIdentifier: "com.madebymist.qdb-ios")
  let app2 = XCUIApplication(bundleIdentifier: "com.madebymist.qdb-ios")
  app1.launch()
  app1.buttons["Select Group"].tap()
  app1.sheets.buttons["Group one"].tap()
  app1.buttons["Host"].tap()

  // Launch and test App 2
  app2.launch()
  app2.buttons["Select Group"].tap()
  app2.sheets.buttons["Group one"].tap()
  app2.buttons["Join"].tap()

}

But that only launched the app one by one, after each other, in the same Simulator.

So, is there any way to achieve simultaneous XCUITest on multiple Simulator devices? (Preferably within Xcode/Swift, but other options would work as well).

1 Answers

Yes since Xcode 10 you can run parallel testing

  1. Select your target scheme in Xcode, and "Edit Scheme..."
  2. Find the settings for "Test", and press on the "Info" tab
  3. You'll see a list of your Unit and UI tests, press on the associated "Options..." button
  4. Select "Execute in parallel on Simulator"
  5. Optionally select "Randomize execution order"

Options

Related