TerminateProcess Method

Applies to TestComplete 15.44, last modified on November 10, 2022

Description

Use the TerminateProcess method to stop a process running on a mobile device and specified by its name.

Declaration

ApplicationManagerObj.TerminateProcess(ProcessName)

ApplicationManagerObj An expression, variable or parameter that specifies a reference to an ApplicationManager object
ProcessName [in]    Required    String    
Result None

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

ProcessName

Specifies the name of the process that you want to terminate.

For iOS, it is the bundle ID of the application that started the process. For example, com.apps.orders.

For Android, it is the name of the package that corresponds to the process. For example, com.example.orders.

Result Value

None.

Example

The code below shows how to get the ApplicationManager object and how to use it to manage a process running on a mobile device:

Note: For the example to work correctly, your project must be connected to the BitBar cloud, the bitbar_app capability must specify the correct application ID in the BitBar file storage, and the processName variable must specify the proper name of the process existing on the connected mobile device. If you use an iOS device, the bundleId capability must also be specified for the testing session. See Project Properties - Device Cloud > Mobile.

JavaScript

function Test()
{

  // Connect to a mobile device
  var capabilities = {
  "platformName": "ANDROID",
  "bitbar_target": "android",
  "bitbar_findDevice": "false",
  "bitbar_device": "Google Pixel 3a Android 10",
  "deviceName": "Google Pixel 3a Android 10",
  "automationName": "UiAutomator2",
  "bitbar_app": "1234"
};
  var server = "https://appium.bitbar.com/wd/hub/";
  Mobile.ConnectDevice(server, capabilities);

  var appManager = Mobile.Device().ApplicationManager;
  var processName = "smartbear.example.orders";

  // Launch the tested application
  appManager.LaunchTestedApp();

  // Switch the tested application to the background mode
  appManager.BackgroundTestedApp();
  // Post the process state to the test log
  Log.Message(appManager.ProcessState(processName));

  // Restore the process of the tested application from the background
  appManager.ActivateProcess(processName);

  // Terminate the process of the tested application
  appManager.TerminateProcess(processName);

}

JScript

function Test()
{
  // Connect to a mobile device
  var capabilities = "{\"platformName\":\"ANDROID\",\"bitbar_target\":\"android\",\"bitbar_findDevice\":false,\"bitbar_device\":\"Google Pixel 3a Android 10\",\"deviceName\":\"Google Pixel 3a Android 10\",\"automationName\":\"UiAutomator2\",\"bitbar_app\":\"1234\"}";
  var server = "https://appium.bitbar.com/wd/hub/";
  Mobile.ConnectDevice(server, capabilities);

  var appManager = Mobile.Device().ApplicationManager;
  var processName = "smartbear.example.orders";

  // Launch the tested application
  appManager.LaunchTestedApp();

  // Switch the tested application to the background mode
  appManager.BackgroundTestedApp();

  // Post the process state to the test log
  Log.Message(appManager.ProcessState(processName));

  // Restore the process of the tested application from the background
  appManager.ActivateProcess(processName);

  // Terminate the process of the tested application
  appManager.TerminateProcess(processName);

}

Python

def Test():

  # Connect to a mobile device
  capabilities = {
    "platformName": "ANDROID", 
    "bitbar_target": "android", 
    "bitbar_findDevice": "false", 
    "bitbar_device": "Google Pixel 3a Android 10", 
    "deviceName": "Google Pixel 3a Android 10", 
    "automationName": "UiAutomator2", 
    "bitbar_app": "1234"
}
  server = "https://appium.bitbar.com/wd/hub/"
  Mobile.ConnectDevice(server, capabilities)

  appManager = Mobile.Device().ApplicationManager
  processName = "smartbear.example.orders"
  
  # Launch the tested application
  appManager.LaunchTestedApp()
  
  # Switch the tested application to the background mode
  appManager.BackgroundTestedApp()
  
  # Post the process state to the test log
  Log.Message(appManager.ProcessState[processName])
  
  # Restore the process of the tested application from the background
  appManager.ActivateProcess(processName)
  
  # Terminates the process of the tested application
  appManager.TerminateProcess(processName)

VBScript

Sub Test()

  ' Connect to a mobile device
  capabilities = "{""platformName"":""ANDROID"",""bitbar_target"":""android"",""bitbar_findDevice"":false,""bitbar_device"":""Google Pixel 3a Android 10"",""deviceName"":""Google Pixel 3a Android 10"",""automationName"":""UiAutomator2"",""bitbar_app"":""1234""}"
  server = "https://appium.bitbar.com/wd/hub/"
  Call Mobile.ConnectDevice(server, capabilities)

  Set appManager = Mobile.Device().ApplicationManager
  processName = "smartbear.example.orders"

  ' Launch the tested application
  appManager.LaunchTestedApp

  ' Switch the tested application to the background mode
  appManager.BackgroundTestedApp

  ' Post the process state to the test log
  Log.Message(appManager.ProcessState(processName))

  ' Restore the process of the tested application from the background
  appManager.ActivateProcess(processName)

  ' Terminate the process of the tested application
  appManager.TerminateProcess(processName)

End Sub

DelphiScript

def Test():

  # Connect to a mobile device
  capabilities = {
    "platformName": "ANDROID",
    "bitbar_target": "android",
    "bitbar_findDevice": "false",
    "bitbar_device": "Google Pixel 3a Android 10",
    "deviceName": "Google Pixel 3a Android 10",
    "automationName": "UiAutomator2",
    "bitbar_app": "1234"
}
  server = "https://appium.bitbar.com/wd/hub/"
  Mobile.ConnectDevice(server, capabilities)

  appManager = Mobile.Device().ApplicationManager
  processName = "smartbear.example.orders"

  # Launch the tested application
  appManager.LaunchTestedApp()

  # Switch the tested application to the background mode
  appManager.BackgroundTestedApp()

  # Post the process state to the test log
  Log.Message(appManager.ProcessState[processName])

  # Restore the process of the tested application from the background
  appManager.ActivateProcess(processName)

  # Terminate the process of the tested application
  appManager.TerminateProcess(processName)

C++Script, C#Script

function Test()
{
  // Connect to a mobile device
  var capabilities = "{\"platformName\":\"ANDROID\",\"bitbar_target\":\"android\",\"bitbar_findDevice\":false,\"bitbar_device\":\"Google Pixel 3a Android 10\",\"deviceName\":\"Google Pixel 3a Android 10\",\"automationName\":\"UiAutomator2\",\"bitbar_app\":\"1234\"}";
  var server = "https://appium.bitbar.com/wd/hub/";
  Mobile["ConnectDevice"](server, capabilities);

  var appManager = Mobile["Device"]()["ApplicationManager"];
  var processName = "smartbear.example.orders";

  // Launch the tested application
  appManager["LaunchTestedApp"]();

  // Switch the tested application to the background mode
  appManager["BackgroundTestedApp"]();

  // Post the process state to the test log
  Log["Message"](appManager["ProcessState"](processName));

  // Restore the process of the tested application from the background
  appManager["ActivateProcess"](processName);

  // Terminate the process of the tested application
  appManager["TerminateProcess"](processName);

}

See Also

ApplicationManager Object

Highlight search results