BackgroundTestedApp Method

Applies to TestComplete 15.0, last modified on November 17, 2021

Description

Use the BackgroundTestedApp method to switch the tested application running on the mobile device to the background mode.

Declaration

ApplicationManagerObj.BackgroundTestedApp()

ApplicationManagerObj An expression, variable or parameter that specifies a reference to an ApplicationManager object
Result None

Applies To

The method is applied to the following object:

Result Value

None.

Example

The code below shows how to get the ApplicationManager object and how to use it to start, reset, and then stop the tested application for which the testing session is opened on the mobile device:

Note: For the example to work correctly, your project must be connected to the BitBar cloud and the bitbar_app capability must specify a correct application ID in the BitBar file storage. If you use an iOS device, the bundleId capability must also be specified for the testing session. See Project Properties - BitBar and Local Appium .

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;
  // Launch the tested application
  appManager.LaunchTestedApp();

  // Simulate user actions
  // …

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

  // Reset and restart the tested application
  appManager.ResetTestedApp();
  // …

  // Close the tested application and stop the testing session
  appManager.CloseTestedApp();

}

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;
  // Launch the tested application
  appManager.LaunchTestedApp();

  // Simulate user actions
  // …

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

  // Reset and restart the tested application
  appManager.ResetTestedApp();
  // …

  // Close the tested application and stop the testing session
  appManager.CloseTestedApp();

}

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
  
  # Launch the tested application
  appManager.LaunchTestedApp

  # Simulate user actions
  # ...

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

  # Reset and restart the tested appication
  appManager.ResetTestedApp
  # ...

  # Close the tested application and stop the testing session
  appManager.CloseTestedApp

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
  ' Launch the tested application
  appManager.LaunchTestedApp

  ' Simulate user actions
  ' …

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

  ' Reset and restart the tested application
  appManager.ResetTestedApp
  ' …

  ' Close the tested application and stop the testing session
  appManager.CloseTestedApp

End Sub

DelphiScript

procedure Test();
var capabilities, server, appManager;
begin

  // 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;
  // Launch the tested application
  appManager.LaunchTestedApp();

  // Simulate user actions
  // …

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

  // Reset and restart the tested application
  appManager.ResetTestedApp();
  // …

  // Close the tested application and stop the testing session
  appManager.CloseTestedApp();

end;

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"];
  // Launch the tested application
  appManager["LaunchTestedApp"]();

  // Simulate user actions
  // …

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

  // Reset and restart the tested application
  appManager["ResetTestedApp"]();
  // …

  // Close the tested application and stop the testing session
  appManager["CloseTestedApp"]();

}

See Also

ApplicationManager Object

Highlight search results