Getting Started with Espresso Testing

What Is Espresso?

Espresso is a testing framework developed by Google for Android devices using AndroidX Test. Espresso provides APIs for writing UI tests and can run on devices running Android 4.0.1 and higher. Espresso provides automatic synchronization of test actions with the UI of the app you are testing, which makes it a popular framework for testers and DevOps teams. 

On the Kobiton UI, the automation settings will return the information needed to connect to Android devices and run an Espresso test from your testing environment. 

 

Espresso Automation Settings

To retrieve the settings needed to run an Espresso Test: 

  1. On the Kobiton portal, navigate to the desired Android device and click on the ellipses icon. 
  2. Click on Automation Settings. mceclip0.png
  3. Fill in the following testing capabilities:
    • Framework: select UIAutomator/Espresso
    • Language: select from Java, .Net C#, NodeJS, Ruby, Python, PHP
    • Session Name: default name is "Automation test session", but it can be customized
    • Description: optional session description
    • Session Timeout: default timeout is 60 minutes, but can be changed to designated time
    • Test Timeout: By default set to 0 minutes, but can be changed to designated time
    • User Team: defaults to user's default user team, but can be changed if executing user is a member of multiple groups
    • Device Team: defaults to device's default device team, but click to open the dropdown for other available teams
    • Use specific device: check the box beside this feature to enable the use of only the specified iOS device
    • Continue on failure: check the box beside this feature to enable Kobiton to continue the test if possible even if a step fails
    • Clean up device on exit (private/local only): check the box beside this feature to enable the device clean-up plan you've selected for your org to run on this device once the test completes
    • App: select which app access method you prefer: either upload an application with a URL or an application on the Kobiton App Repository, as described below
      • Hybrid/Native from URL
        • Application URL
      • Hybrid/Native from apps
        • Select App from Apps Repo
    • Test Runner: enter the URL for the test.apk or use click Upload Test Runner to upload a test.apk file 
    • API Key: Default API key
  4. Use the copy to clipboard icon to copy the generated desired capabilities to your testing files. espresso-test-settings.png
  5. Add the copied capabilities to the configuration of your test script (settings with comments removed).

Example:

This JavaScript Espresso testing example will make a connection to a public Android device through the Kobiton portal. To view this project on Github, click here

const request = require("request");

const username = "kobiton.username";
const apiKey = "dd21c1-6124-5223-9b8a-51e01b41263e";

const encodeAuth = `Basic ${Buffer.from(`${username}:${apiKey}`).toString('base64')}`;

const configuration = {
sessionName:"Espresso automation test session",
sessionDescription:"Espresso testing example",
deviceName:"Galaxy A20",
platformVersion:"9",
groupId:905,
deviceGroup:"KOBITON",
app:"https://kobiton-devvn.s3-ap-southeast-1.amazonaws.com/apps-test/uiautomator-espresso/espresso-app.apk",
testRunner:"https://kobiton-devvn.s3-ap-southeast-1.amazonaws.com/apps-test/uiautomator-espresso/esspresso-test-runner.apk",
continueOnFailure:true,
testFramework:"UIAUTOMATOR"
};

const headers = {
'Content-Type':'application/json',
'Authorization':encodeAuth,
'Accept':'application/json'
};

constbody = {
configuration
};

request ({
url:"https://api.kobiton.com/hub/session",
json:true,
method:'POST',
body,
headers
},

function (err, response, body) {
if (err) returnconsole.error ("Error:", err);
console.log('Response body:', body);
});

Play the video to watch what to expect from this test sample:

 

Was this article helpful?
0 out of 0 found this helpful