Skip to main content

Espresso Server is an application installed on device which enables Espresso test execution.

Before the first test execution, the Espresso server must be built for specific application under test.

For each application under test, there is a special Espresso Server matching this application.

For more information about Appium Espresso driver, see the Appium Espresso Driver documentation.

info

As per the Appium documentation, the Espresso server should be built by developers.

To prepare for the first Espresso test run in the Cloud:

  1. Build Espresso Server using a local Appium Server (should be done only once for application under test).
  2. Upload Espresso Server to the Cloud with a unique name (should be done only once for application under test).
  3. Run the test with the espressoServerUniqueName capability.

Install and Run Appium Server

To install the Appium Server with the Espresso driver, run these commands:

  • npm install -g appium@next
  • appium driver install espresso

To make sure you are running Appium Server 2.x, run: appium -v

To run the Appium Server, run: appium

For more details see the Appium Documentation.

Build the Espresso Server

To build the Espresso server:

  1. Set the Espresso driver type.

    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("automationName", "Espresso");
  2. Set the application under test.

    capabilities.setCapability("app", "/Users/OEpstein/Downloads/JetSurvey.apk");

    Example of Espresso Server Build Configuration:

    capabilities.setCapability("appium:forceEspressoRebuild", true); // Default is false
    capabilities.setCapability("appium:showGradleLog", true); // Default is false
    capabilities.setCapability("espressoBuildConfig", "{\"toolsVersions\": " +
    "{\"compileSdk\":31} ," +
    "\"additionalAndroidTestDependencies\": " +
    "[\"androidx.compose.runtime:runtime:1.1.1\" , " +
    "\"androidx.compose.ui:ui-tooling:1.1.1\" , " +
    "\"androidx.compose.foundation:foundation:1.1.1\" , " +
    "\"androidx.compose.material:material:1.1.1\" ] }");
  3. Set compose mode in order to test JetPack application.

    driver = new AndroidDriver(new URL(APPIUM_SERVER_URL), capabilities);
    driver.setSetting("driver", "compose");
    // Test code...
    driver.quit();
  4. Uninstall Espresso Server from Android device, so that Appium Server installs it.

    adb uninstall io.appium.espressoserver.test
  5. Run the test. It generates the Espresso server.

To see where the Espressor server is located, check the in Appium server log.

Appium Server Log Example

[EspressoDriver@39f7 (d53ddc1e)] Installing Espresso Test Server apk from the target device (path: '/var/folders/03/n6jdys956n1d_7wyznsmzpd00000gp/T/io.appium.espressoserver.test_2.2.2_com.example.compose.jetsurvey_899X07061.apk')

This APK file should be uploaded to the Cloud server.

Upload the Espresso Server to the Cloud Server

  1. Navigate to Applications in the Cloud.

  2. Provide unique name.

Run the Test With the espressoServerUniqueName Capability

Provide the capability in each test.

capabilities.setCapability("espressoServerUniqueName", "espresso_jetsurvey");

Now the test can be executed on cloud devices.

Example Code for Building an Espresso Server

package jetpack;

import io.appium.java_client.AppiumBy;
import io.appium.java_client.android.AndroidDriver;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.MalformedURLException;
import java.net.URL;

public class JetpackBuildServerTest {

/**
* Appium Server must have version 2.x
* Appium Client must have version 8.x (Gradle dependency: implementation 'io.appium:java-client:8.0.0')
*/
public static final String APPIUM_SERVER_URL = "http://localhost:4723"; // Local Appium server
private static AndroidDriver driver;
private static final DesiredCapabilities capabilities = new DesiredCapabilities();

@BeforeAll
public static void setUp() throws MalformedURLException {
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("automationName", "Espresso");
capabilities.setCapability("app", "/Users/OEpstein/Downloads/JetSurvey.apk");

/**
* Capabilities for Espresso Server build
* Test dependencies should be provided by JetPack application developers.
* Dependencies versions must match the versions in application under test.
*/
capabilities.setCapability("appium:forceEspressoRebuild", true); // Default is false
capabilities.setCapability("appium:showGradleLog", true); // Default is false
capabilities.setCapability("espressoBuildConfig", "{\"toolsVersions\": " +
"{\"compileSdk\":31} ," +
"\"additionalAndroidTestDependencies\": " +
"[\"androidx.compose.runtime:runtime:1.2.0-alpha08\" , " +
"\"androidx.compose.ui:ui-tooling:1.2.0-alpha08\" , " +
"\"androidx.compose.foundation:foundation:1.2.0-alpha08\" , " +
"\"androidx.compose.material:material:1.2.0-alpha08\" ] }");

driver = new AndroidDriver(new URL(APPIUM_SERVER_URL), capabilities);
driver.setSetting("driver", "compose");
}

@Test
public void jetSurvey() {
// Espresso server is created during Appium driver creation.
}

@AfterAll
public static void tearDown() {
if (driver != null)
driver.quit();
}
}

Example Test Code

import io.appium.java_client.AppiumBy;
import io.appium.java_client.android.AndroidDriver;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.MalformedURLException;
import java.net.URL;

public class JetpackDemoTest {
public static final String APPIUM_SERVER_URL = "http://<host:port>/wd/hub";
public static final String CLOUD_ACCESS_KEY = "<access key>";
private static AndroidDriver driver;
private static final DesiredCapabilities capabilities = new DesiredCapabilities();

@BeforeAll
public static void setUp() throws MalformedURLException {
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("automationName", "Espresso");

capabilities.setCapability("accessKey", CLOUD_ACCESS_KEY);
capabilities.setCapability("deviceQuery", "@os='android'");
capabilities.setCapability("appium:appiumVersion", "2.0.0.beta.23");
capabilities.setCapability("app", "cloud:com.example.compose.jetsurvey/.MainActivity");
capabilities.setCapability("testName", "Appium 2.x Espresso driver in compose mode");

/**
* Espresso server with this unique name must exist in cloud project
*/
capabilities.setCapability("espressoServerUniqueName", "espresso_jetsurvey");

driver = new AndroidDriver(new URL(APPIUM_SERVER_URL), capabilities);
driver.setSetting("driver", "compose");
}

@Test
public void jetSurvey() {
WebElement email = driver.findElement(AppiumBy.tagName("emailTag"));
email.click();
email.sendKeys("guest@example.com");
WebElement continueButton = driver.findElement(AppiumBy.tagName("continueTag"));
continueButton.click();
}

@AfterAll
public static void tearDown() {
if (driver != null)
driver.quit();
}
}

Limitations

  • It is not possible to open Mobile Studio during Espresso test execution.

  • The Espresso driver is supported only for Appium versions 2.x (and Appium Java client 8).

Troubleshooting

ProblemPossible Solution
The following message appears in console:



espressoServerUniqueName capability must be provided for Appium Espresso tests
Provide the required capability.
The following error appears in Appium Server log: 



Cannot launch activity
Uninstall the previous application under test on Android device.
The following error appears in Appium Server log: INSTRUMENTATION_STATUS: Error=Unable to find instrumentation target package:Incorrect Espresso server was used for the application under test. Verify that Espresso Server matches the application under test.
The following error appears in Appium Server log:



java.lang.NoSuchMethodError:



No static method isTraceInProgress()Z in class Landroidx/compose/runtime/ComposerKt
* Incorrect Espresso server was used for the application under test.

* Espresso server was built with incorrect dependencies (or incorrect versions of dependencies).
The following error appears in Appium Server log:



Got response with status 500: {"id":"5ae1278b-b8b0-4986-972a-ed2a92d6e258","sessionId":"b2bc2c1e-4370-4e44-80b2-dcca88ae11cb","value":{"error":"unknown error","message":"java.lang.NoSuchMethodError: No virtual method replace(ILjava/lang/Object;)Ljava/lang/Object; in class Landroidx/collection/SparseArrayCompat
Espresso server was built without the required dependencies.



Provide additional dependencies in the espressoBuildConfig capability when building the Espresso server.