Run XCUI tests

Step 1: Prepare an App

The Application .ipa file should be created in the Xcode:

  • Open your app project.
  • Select Any iOS Device (arm64) as your product’s device target.
  • In the Product menu, select Clean Build Folder.
  • In the Product menu, select Archive. You’ll see your app listed under Archives when the archiving process completes.
  • Select your app and click Distribute.
  • Select Ad Hoc, Enterprise, or Development when prompted for an export method.
  • Set Distribution options if necessary or leave default values
  • Select your Distribution Certificate and Provisioning Profile (Automatic or Manual). This will generate the .ipa file.
  • When the file generation process completes, click Export and choose where to save the .ipa file.

Step 2: Prepare a Test Suite app

Ensure you set the same iOS version for your app and test runner iOS Deployment Target. If not, your tests will run locally, but fail when you run them against Mobitru devices.

To set the iOS version in your Xcode Project:

  • Select the Project in the IDE.
  • Select Build Settings and set the iOS Deployment Target to the iOS version you want to use in your test

To set the iOS version in your Xcode Target:

  • Select the Tests Target for your Project.
  • Select Build Settings and set the iOS Deployment Target to the iOS version you want to use in your test

Prepare an .ipa with Tests:

  • Open your app project in the IDE.
  • Select Any iOS Device (arm64) as your product’s device target.
  • In the Product menu, select Clean Build Folder..
  • In the Product menu, select Build For -> Testing.
  • Navigate in a Terminal to your Xcode project’s Products directory and find the generated .app archive with tests.
  • Finish preparing of an .ipa file
    • Create a Payload directory using: mkdir Payload
    • Move the .app to the created directory: mv <file_name>.app Payload 
    • Compress the Payload directory into an archive (.zip file): zip -r <archive_name>.zip Payload
    • Change the .zip extension to the .ipa in the result file

Step 3: Upload the App and the Test Suite

Upload your Application and Test Suites apps to Mobitru using our REST API.

Retrieve and store the id of every uploaded .ipa, because it will be used to trigger an Execution.

Here is an example cURL request to upload the app :

curl --location --request POST 'https://app.mobitru.com/billing/unit/<BILLING_UNIT>/automation/api/v1/spaces/artifacts' \
--header 'x-File-Name: <app_name>.ipa' \
--header 'X-Content-Type: application/zip' \
--header 'Authorization: Bearer <ACCESS_KEY>' \
--form 'file=@"/path/to/app/file/app.ipa"' \
--form 'checksum="None"'

Below you can find a sample of the response with an id of the uploaded app:

{
    "id": "de807b5a-54c6-4198-90cb-d4a4f1932897",
    "name": "909e222a-a41d-4f71-af7e-5fe4c7a56614.ipa",
    "realName": "<app_name>.ipa",
    "bid": "7a21f4ad-e322-43e2-9649-0209de6a9752",
    "wid": "0",
    "private": true,
    "uploadedBy": "<user_name>@test.com",
    "uploadedAt": 1672081608,
    "verified": false,
    "target": "ios",
    "contentType": "application/zip",
    "contentLength": 0,
    "href": "quarantine/909e222a-a41d-4f71-af7e-5fe4c7a56614.ipa",
    "checksum": "None",
    "alias": "<app_name>",
    "apk": null,
    "ipa": null
}

Step 4: Find and take device

Find and take appropriate device using our APIs.

Here is an example of cURL request to find a device via API:

curl --location --request GET 'https://app.mobitru.com/billing/unit/<BILLING_UNIT>/automation/api/device/ios?version=16.2' \
--header 'Authorization: Bearer <ACCESS_KEY>'

Below you can find a sample of the response with capabilities for found devices:

[
    {
        "desiredCapabilities": {
            "platformName": "iOS",
            "platformVersion": "16.2",
            "deviceName": "IPHONE iPhone13,3",
            "udid": "00008101-00042D8A1190001E",
            "automationName": "XCUITest"
        }
    },
    {
        "desiredCapabilities": {
            "platformName": "iOS",
            "platformVersion": "16.2",
            "deviceName": "IPAD iPad12,1",
            "udid": "00008030-001E79460A10C02E",
            "automationName": "XCUITest"
        }
    },
    {
        "desiredCapabilities": {
            "platformName": "iOS",
            "platformVersion": "16.2",
            "deviceName": "IPHONE iPhone13,2",
            "udid": "00008101-001219601A51003A",
            "automationName": "XCUITest"
        }
    }
]

Here is an example of cURL request to take a device via API:

curl --location --request POST 'https://app.mobitru.com/billing/unit/<BILLING_UNIT>/automation/api/device/00008101-00042D8A1190001E' \
--header 'Authorization: Bearer <ACCESS_KEY>'

Below you can find a sample of the response with capabilities for the device:

{
    "desiredCapabilities": {
        "platformName": "iOS",
        "platformVersion": "16.2",
        "deviceName": "IPHONE iPhone13,3",
        "udid": "00008101-00042D8A1190001E"
    }
}

Step 5: Run tests

After taking a Device, you can run your XCUI tests using all existing information.

Here is an example of cURL a request to run the tests:

curl --location --request POST 'https://app.mobitru.com/billing/unit/<BILLING_UNIT>/automation/api/v1/tests/xcuitest' \
--header 'Authorization: Bearer <ACCESS_KEY>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "serial": "00008101-00042D8A1190001E",
    "app_artifact_id": "<app_ipa_artifact_id>",
    "test_artifact_id": "<tests_ipa_artifact_id>",
    "resign":true
}'

Below you can find a sample of the response with the Run ID:

{
    "id": "2b3b6a44-a3ae-4176-ae97-ca56e50ef6a1",
    "engine": "xcuitest",
    "status": "pending",
    "config": {
        "serial": "00008101-00042D8A1190001E",
        "app_artifact_id": "<APP_IPA_ARTIFACT_ID>",
        "test_artifact_id": "<TESTS_IPA_ARTIFACT_ID>",
        "resign": true
    },
    "summary": "",
    "artifacts": {},
    "created_at": "yyyy-mm-ddT19:16:41.598897Z",
    "updated_at": "yyyy-mm-ddT19:16:41.598897Z"
}

If necessary, you can cancel pending execution by performing of separate API:

Here is an example of cURL request to cancel the Execution:

curl --location --request PUT 'https://app.mobitru.com/billing/unit/<BILLING_UNIT>/automation/api/v1/tests/xcuitest/<RUN_ID>/cancel' \
--header 'Authorization: Bearer <ACCESS_KEY>'

As result, you will receive 204 No Content response.

Step 6: Get the Run details

After finishing the Execution, you can get the Run details via API.

Here is an example of cURL request to get such details:

curl --location --request GET 'https://app.mobitru.com/billing/unit/<BILLING_UNIT>/automation/api/v1/tests/xcuitest/<RUN_ID>' \
--header 'Authorization: Bearer <ACCESS_KEY>'

Below you can find a sample of the response with artifacts.log ID:

{
    "id": "<RUN_ID>",
    "engine": "xcuitest",
    "status": "completed",
    "config": {
        "serial": "00008030-001228523A43802E",
        "app_artifact_id": "<APP_IPA_ARTIFACT_ID>",
        "test_artifact_id": "<TESTS_IPA_ARTIFACT_ID>",
        "resign": true
    },
    "summary": "Test run completed",
    "artifacts": {
        "log": "8898c8e9-a2c0-44ea-be05-ff343de23cc0",
        "runner-log": "afe9b0ea-eadc-4ba0-8def-0c5e013a0ba4"
    },
    "created_at": "yyyy-mm-ddT19:16:41.598897Z",
    "updated_at": "yyyy-mm-ddT19:16:41.598897Z"
}

Step 7: Get execution log

Also, you can get a base log via separate API.

Here is an example of cURL request to get such log:

curl --location --request GET 'https://app.mobitru.com/billing/unit/<BILLING_UNIT>/automation/api/v1/spaces/artifacts/<LOG_ID>/download' \
--header 'Authorization: Bearer <ACCESS_KEY>'

Below you can find an example of a response with the log content:

2022-12-26 20:19:36.149316+0100 sample-ios-app-demoUITests-Runner[469:71421] Running tests...
Test Suite 'All tests' started at 2022-12-26 20:19:37.874
Test Suite 'sample-ios-app-demoUITests.xctest' started at 2022-12-26 20:19:37.874
Test Suite 'sample_ios_app_demoUITestsLaunchTests' started at 2022-12-26 20:19:37.875
Test Case '-[sample_ios_app_demoUITests.sample_ios_app_demoUITestsLaunchTests testDeleteWhitespace]' started.
    t =     0.00s Start Test at 2022-12-26 20:19:37.875
  ......
  .......
  .......
  ........
Test Case '-[sample_ios_app_demoUITests.sample_ios_app_demoUITestsLaunchTests testReverseStringOneSymbol]' passed (4.357 seconds).
Test Suite 'sample_ios_app_demoUITestsLaunchTests' passed at 2022-12-26 20:20:28.319.
	 Executed 11 tests, with 0 failures (0 unexpected) in 50.430 (50.444) seconds
Test Suite 'sample-ios-app-demoUITests.xctest' passed at 2022-12-26 20:20:28.321.
	 Executed 11 tests, with 0 failures (0 unexpected) in 50.430 (50.446) seconds
Test Suite 'All tests' passed at 2022-12-26 20:20:28.322.
	 Executed 11 tests, with 0 failures (0 unexpected) in 50.430 (50.449) seconds
Scroll to Top