Common Appium API calls

Use the following Appium API calls to manage your apps or add network virtualization capabilities within UFT Mobile.

Tip: Refer to the UFT Mobile Help Center for more examples.

Kill application

The Kill API call stops the application. It does not simply minimize the app—it terminates the process. The script name is mc:application:kill, and must use one of the following arguments:

  • “appPackage” (Android) or “bundleId” (iOS) as used with the Appium capabilities. For details, see the UFT Mobile Appium Capabilities section in the UFT Mobile Help Center.

  • “id” or “uuid” as used in the UFT Mobile REST API (Install / Uninstall). For details, see the REST API reference for UFT Mobile section in the UFT Mobile Help Center.

The following sample code terminates the Advantage app:

Map<String, Object> params = new HashMap<String, Object>();
params.put("bundleId", "com.Advantage.aShopping");
appiumDriver.executeScript("mc:application:kill", params);

Back to top

Change a network virtualization profile

This API call lets you switch emulated networks while a test is running, to test and compare your app's behavior under different network conditions.

The available parameters are:

  • “profileName” (required) as described in Define NV profiles. For details, see the Define NV profiles section in the UFT Mobile Help Center.

  • “scenarioName” (optional) a name for the scenario. If you leave out this parameter, the scenario uses the name of the profile.

The following sample code switches to an emulation of a 4G typical network:

Map<String,String> map = new HashMap<>();
map.put("profileName", "4G typical");
driver.executeScript("mc:net:changeProfile", map);

Back to top

Generate a network virtualization report

This API call stops the NV emulation and retrieves the NV Analytics HTML report as a zip file encoded as a base64 string. The script name is mc:net:getReport and uses no parameters.

Note: Calling this API stops NV emulation, therefore the rest of your Appium test will run without network emulation.

The following sample code generates the nv_report.zip file containing the NV Analytics HTML report.

String fileName = "C:\\nv_report.zip";
Object response = driver.executeScript("mc:net:getReport");
String base64Str = (String) response;
byte[] bytes = Base64.getDecoder().decode(base64Str);
IOUtils.write(bytes, new FileOutputStream(new File(fileName)));

Back to top

Generate a network virtualization HAR (HTTP Archive) file

This API call stops the NV emulation and retrieves the HAR file captured by the Network Virtualization proxy, as a zip file encoded in base64. You can use the HAR file to create a test in LoadRunner Cloud or in LoadRunner Professional to generate mobile load testing scripts.

The script name is mc:net:getHAR and uses no parameters.

Note: Calling this API stops NV emulation, therefore the rest of your Appium test will run without network emulation.

The following sample generates the nv_har.zip archive file, containing the HAR file.

String fileName = "C:\\nv_har.zip";
Object response = driver.executeScript("mc:net:getHAR");
String base64Str = (String) response;
byte[] bytes = Base64.getDecoder().decode(base64Str);
IOUtils.write(bytes, new FileOutputStream(new File(fileName)));

Back to top

See also: