Skip to main content

XCUI Testing on LambdaTest


Developed by Apple, XCUITest is a framework for user-interface (UI) testing for iOS applications. It is built on top of XCTest, an integrated test framework in Apple's Xcode IDE. LambdaTest lets you perform automated app testing of your iOS apps using XCUITest across 3000+ real devices and OS combinations.

Objective​


By the end of this topic, you will be able to:

  1. Run a sample automation script of an XCUI Test.
  2. Learn more about capabilities supported for XCUI Testing.

Prerequisites for Getting Started​


  1. You will need a LambdaTest username and access key. To obtain your access credentials, purchase a plan or access the automation dashboard.
  2. Access to an iOS app (.ipa) and an XCUI Test app (.ipa file).
tip

If you do not have any iOS app (.ipa) and an XCUI Test app (.ipa) file, you can run your sample tests on LambdaTest by using our sample 🔗 iOS app and a sample 🔗 XCUI Test.

Run Your First Test​


Step 1: Upload Your Application​

Upload your iOS application (.ipa file) to the LambdaTest servers using our REST API. You need to provide your Username and AccessKey in the format Username:AccessKey in the cURL command for authentication. Make sure to add the path of the appFile in the cURL request.

Here is an example cURL request to upload your app using our REST API:

Using App File:

curl -u "undefined:undefined" \
--location --request POST 'https://manual-api.lambdatest.com/app/uploadFramework' \
--form 'appFile=@"/Users/macuser/Downloads/proverbial.ipa"' \
--form 'type="xcuit-ios"'
note

Response of above cURL will be a JSON object containing the App URL of the format - lt://APP123456789123456789 and will be used in the last step.

Step 2: Uploading Test Suite​

Upload your test suite (.ipa file) to the LambdaTest servers using our REST API. You need to provide your Username and AccessKey in the format Username:AccessKey in the cURL command for authentication. Make sure to add the path of the appFile in the cURL request. Here is an example cURL request to upload your app using our REST API:

Using App File:

curl -u "undefined:undefined" \
--location --request POST 'https://manual-api.lambdatest.com/app/uploadFramework' --form 'appFile=@"/Users/macuser/Downloads/proverbial_ios_xcuitest.ipa"' --form 'type="xcuit-ios"'
note

Response of above cURL will be a JSON object containing the App URL of the format - lt://APP123456789123456789 and will be used in the next step.

Step 3: Executing The Test​

Basic Authentication​

info

You will need base64 encoded authentication in order to execute your XCUI automation test suite. You need to enter your username:accesskey here in order and click on encode to generate the base64 authentication. Take note of the base64 encoded authentication which needs to be added in the next step.

undefined:undefined

Execute Command​

Once you have uploaded your app and test suite, you need to you can execute your test by running the following command:

info

Make sure to enter your basic authentication, app url (generated in the first step) and testSuite url (generated in the second step) in the below command.

curl --location --request POST 'https://mobile-api.lambdatest.com/framework/v1/xcui/build' \
--header 'Authorization: Basic <Enter_Basic_Auth>' \
--header 'Content-Type: application/json' \
--data-raw '{
"app" : "lt://APP_ID",
"testSuite": "lt://TestSuite_ID",
"device" : ["iPhone 11-14"],
"video" : true,
"queueTimeout": 10800,
"idleTimeout": 150,
"devicelog": true,
"network": false,
"build" : "Proverbial-XCUITest"
}'

Step 4: View Test Execution​

Once you have run your tests, you can view the test execution along with logs. You will be able to see the test cases passing or failing. You can view the same at LambdaTest Automation.

Capabilities Supported​


The following capabilities are supported:

  1. app - Enter the app id generated while uploading the app. Example: lt://APP123456789123456789

  2. testSuite - Enter the test suite id generated while uploading the test suite. Example: lt://APP123456789123456789

  3. device - Enter the name and os version of the device in "DeviceName-OSVersion" format. Example: iPhone 11-14 or iPhone 13 Pro Max-14

  4. video - Generate video for all the tests that have run. Example: true

  5. queueTimeout - Enter the time in seconds after which you want your build to timeout from queue. Example: 300

  6. idleTimeout - Enter the time in seconds for maximum running time on a test in the build. Example: 120

  7. deviceLog - Boolean value to generate device logs. Example: true

  8. network - Boolean value to generate network logs. Example: false

  9. build - Set the name of the Espresso test build. Example: My XCUITEST Build

  10. geoLocation - Set the geolocation country code if you want to enable the same in your test. Example - FR

  11. tunnel, tunnelName - Set tunnel as true and provide the tunnelName such as NewTunnel as needed if you are running a tunnel.

  12. resignApp - Set this to false if you wish to prevent the apps from being re-signed. The app should be built for enterprise distribution.

Important

Only one of GeoLocation or Tunnel must be used in single execute command.

Running Tests In Parallel​


You can run tests in parallel on multiple devices by passing the device name in comma separated format in the execute the command as shown below:

curl --location --request POST 'https://mobile-api.lambdatest.com/framework/v1/xcui/build' \
--header 'Authorization: Basic <Enter_Basic_Auth>' \
--header 'Content-Type: application/json' \
--data-raw '{
"app" : "lt://APP_ID",
"testSuite": "lt://TestSuite_ID",
"device" : ["iPhone 11-14","iPhone 12 Pro-15","iPhone X-13"],
"queueTimeout": 10800,
"IdleTimeout": 150,
"deviceLog": true,
"build" : "Proverbial-XCUITest"
}'

Setting Locale and Language​


You can also configure both locale and language during XCUI test execution for a seamless user experience in diverse linguistic and regional contexts of your app.

Language

To test a localized version of your app on LambdaTest, use the language parameter in the XCUI test execution API request. This allows you to change the language of the application under test.

ParameterDescriptionValues
languageSet the language of the app under testExample: ‘hi’

Locale

To test a localized version of your app on LambdaTest, use the locale parameter in the XCUI test execution API request. This allows you to set the locale for the application under test.

ParameterDescriptionValues
localeSet locale for the app under testExample: IN (Country name abbreviation)

For Example:

curl --location --request POST 'https://mobile-api.lambdatest.com/framework/v1/xcui/build' \
--header 'Authorization: Basic <Enter_Basic_Auth>' \
--header 'Content-Type: application/json' \
--data-raw '{
"app" : "lt://APP_ID",
"testSuite": "lt://TestSuite_ID",
"device" : ["iPhone 11-14"],
"video" : true,
"queueTimeout": 10800,
"idleTimeout": 150,
"devicelog": true,
"network": false,
"build" : "Proverbial-XCUITest",
"language": "fr",
"locale": "CA"
}'
note
  • Ensure that both the language and locale parameters are passed simultaneously in the API request.
  • App should support the language and locale mentioned in the API request to work.
  • For XCUI sharding tests, you have to mention this in the .yaml file.