Espresso Testing On LambdaTest
Espresso is a testing framework that allows developers to write automation test cases for user interface (UI) testing. Developed by Google and free to use, Espresso aims to provide a simple yet powerful framework to help automate the process of testing Android apps.
Objective
By the end of this topic, you will be able to:
- Run a sample automation script of an Espresso Test
- Learn more about capabilities supported for Espresso testing.
Prerequisites for Getting Started
- You will need a LambdaTest username and access key. To obtain your access credentials, purchase a plan or access the automation dashboard.
- Access to an Android app (.apk) and an Espresso Test app (.apk file).
If you do not have any Android app (.apk) and an Espresso Test app (.apk) file, you can run your sample tests on LambdaTest by using our sample 🔗 Android app and a sample 🔗 Espresso Test.
Run Your First Test
Step 1: Upload Your Application
Upload your android application (.apk 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:
- Linux / MacOS
- Windows
curl -u "undefined:undefined" \
--location --request POST 'https://manual-api.lambdatest.com/app/uploadFramework' --form 'appFile=@"/Users/macuser/Downloads/proverbial_android.apk"' --form 'type="espresso-android"'
curl -u "undefined:undefined" --location --request POST "https://manual-api.lambdatest.com/app/uploadFramework" --form "appFile=@"C:/Users/varunkumarb/Downloads/proverbial_android.apk"" --form "type="espresso-android""
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 (.apk 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:
- Linux / MacOS
- Windows
curl -u "undefined:undefined" \
--location --request POST 'https://manual-api.lambdatest.com/app/uploadFramework' --form 'appFile=@"/Users/macuser/Downloads/proverbial_android_expressotest.apk"' --form 'type="espresso-android"'
curl -u "undefined:undefined" --location --request POST "https://manual-api.lambdatest.com/app/uploadFramework" --form "appFile=@"C:/Users/varunkumarb/Downloads/proverbial_android_expressotest.apk"" --form "type="espresso-android""
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
You will need base64 encoded authentication in order to execute your Espresso 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:
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.
- Linux / MacOS
- Windows
curl --location --request POST 'https://mobile-api.lambdatest.com/framework/v1/espresso/build' \
--header 'Authorization: Basic <Enter_Basic_Auth>' \
--header 'Content-Type: application/json' \
--data-raw '{
"app" : "lt://APP_ID",
"testSuite": "lt://TestSuite_ID",
"device" : ["Galaxy S21 5G-12"],
"queueTimeout": 10800,
"IdleTimeout": 150,
"deviceLog": true,
"network": false,
"build" : "Proverbial-Espresso"
}'
curl --location --request POST "https://mobile-api.lambdatest.com/framework/v1/espresso/build" --header "Content-Type: application/json" --header "Authorization: Basic <Enter the Auth here>" --data-raw "{\"app\" : \"lt://APP_ID\",\"testSuite\": \"lt://APP_ID\",\"device\" : [\"Pixel 6-12\"],\"queueTimeout\": 360,\"IdleTimeout\": 150,\"deviceLog\": true,\"network\": false,\"build\" : \"Proverbial-Espresso\",\"geoLocation\" : \"FR\"}"
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:
- app: Enter the app id generated while uploading the app. Example:
lt://APP123456789123456789
- testSuite: Enter the test suite id generated while uploading the test suite. Example:
lt://APP123456789123456789
- device: Enter the name and os version of the device in “DeviceName-OSVersion” format. Example:
Pixel 3 XL-9
orGalaxy S21 Ultra 5G-11
. - video: Generate video for all the tests that have run. Example:
true
. - queueTimeout: Enter the time in seconds after which you want your build to timeout from queue. Example:
300
. - idleTimeout: Enter the time in seconds for maximum running time on a test in the build. Example:
120
. - deviceLog: Boolean value to generate device logs. Example:
true
. - build: Set the name of the Espresso test build. Example:
My Espresso Build
. - geoLocation: Set the geolocation country code if you want to enable the same in your test. Example -
FR
. - tunnel, tunnelName: Set tunnel as
true
and provide the tunnelName such asNewTunnel
as needed if you are running a tunnel. - disableAnimation: Set this to
true
if you want to disable animations for espresso tests. Default:false
- clearPackageData: Set this to
true
if you want to clear the app data after each test has completed running. Default:false
- singleRunnerInvocation: Set this to
true
if you want to execute test cases together with asingle test runner invocation
.This can help significantly speed up the test execution time. By default, each test case is invoked separately. Default:false
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 command as show below:
curl --location --request POST 'https://mobile-api.lambdatest.com/espresso/v1/build' \
--header 'Authorization: Basic <Enter_Basic_Auth>' \
--header 'Content-Type: application/json' \
--data-raw '{
"app" : "app_id",
"testSuite": "testsuite_id",
"device" : ["Galaxy S20-10","Galaxy S20-10","Redmi Note 9-10","Galaxy S10+-10","Galaxy S7 edge-8","Galaxy S9+-8"],
"queueTimeout": 10800,
"IdleTimeout": 150,
"deviceLog": true,
"build" : "Proverbial-Espresso"
}'