3

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).

Curiosity
  • 544
  • 1
  • 15
  • 29
eivindml
  • 2,197
  • 7
  • 36
  • 68

1 Answers1

8

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

  • Awesome, thank you. Is there a way to pause the apps to continue with manual UI testing? Right now I'm just using `sleep(1000)`, but it's an ugly hacks. – eivindml Nov 10 '18 at 11:32
  • And to add for others seeing this, to have multiple simulators running at once, you need to create a new XCUITest class for each Simulator. So basically just duplicate your existing test class, and then Xcode will create duplicates clones of your selected Simulator. – eivindml Nov 10 '18 at 11:33
  • 3
    @eivindml I think you should ask another question about "continue automated UI testing manually" ;) – Mojtaba Hosseini Nov 11 '18 at 06:57
  • 1
    It looks like there is a maximum of three devices. I'm trying to launch five simultaniously, but only three are opened. – eivindml Nov 11 '18 at 20:32