GetApplicationByBundleId Method

Applies to TestComplete 15.70, last modified on December 17, 2024
The information below concerns legacy mobile tests that work with mobile devices connected to the local computer. For new mobile tests, we recommend using the newer cloud-compatible approach.

Description

Use this method to obtain the ApplicationObject object that provides information about the application stored on an iOS device and specified by its bundle identifier.

Declaration

ApplicationManagerObj.GetApplicationByBundleId(BundleIdentifier)

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

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

BundleIdentifier

Specifies the bundle identifier of the desired application installed on the device.

Result Value

The ApplicationObject object that provides information about the application. If no application with the specified bundle identifier is found among the applications installed on the device, the method returns an empty object (null in JavaScript, JScript, C#Script and C++Script, None in Python, Nothing in VBScript, nil in DelphiScript).

Example

The following code checks whether an application is already installed on the device. On success it posts application description to the test log, otherwise it installs the needed application:

JavaScript

function Test()
{
  let appManagerObj = Mobile.Device("iPhone").ApplicationManager;
  // Retrieve application info from the device
  let appObj = appManagerObj.GetApplicationByBundleId("com.example.myapp");

  // Verify whether the application is found
  if (!strictEqual(appObj, null))
    {
    // Display the application information
    Log.Message("The application name is: " + appObj.BundleName);
    Log.Message("The application display name is: " + appObj.BundleDisplayName);
    Log.Message("The package path is: " + appObj.Path);
    }
  else
    // Install the application
    appObj = appManagerObj.InstallApplication("C:\\Work\\MyApp.ipa");

}

JScript

function Test()
{
  var appManagerObj = Mobile.Device("iPhone").ApplicationManager;
  // Retrieve application info from the device
  var appObj = appManagerObj.GetApplicationByBundleId("com.example.myapp");

  // Verify whether the application is found
  if (appObj != null)
    {
    // Display the application information
    Log.Message("The application name is: " + appObj.BundleName);
    Log.Message("The application display name is: " + appObj.BundleDisplayName);
    Log.Message("The package path is: " + appObj.Path);
    }
  else
    // Install the application
    appObj = appManagerObj.InstallApplication("C:\\Work\\MyApp.ipa");

}

Python

def Test():
  appManagerObj = Mobile.Device("iPhone").ApplicationManager
  # Retrieve application info from the device
  appObj = appManagerObj.GetApplicationByBundleId("com.example.myapp")

  # Verify whether the application is found
  if appObj != None:
    # Display the application information
    Log.Message("The application name is: " + appObj.BundleName) 
    Log.Message("The application display name is: " + appObj.BundleDisplayName) 
    Log.Message("The package path is: " + appObj.Path)
  else:
    # Install the application
    appObj = appManagerObj.InstallApplication("C:\\Work\\MyApp.ipa")

VBScript

Sub Test

  Set appManagerObj = Mobile.Device("iPhone").ApplicationManager
  ' Retrieve application info from the device
  Set appObj = appManagerObj.GetApplicationByBundleId("com.example.myapp")

  ' Verify whether the application is found
  If Not appObj Is Nothing Then
    ' Display the application information
    Call Log.Message("The application name is: " + appObj.BundleName)
    Call Log.Message("The application display name is: " + appObj.BundleDisplayName)
    Call Log.Message("The application archive path is: " + appObj.Path)
  Else
    ' Install the application
    Set appObj = appManagerObj.InstallApplication("C:\Work\MyApp.ipa")
  End If

End Sub

DelphiScript

procedure Test();
var appManagerObj, appObj;
begin
  appManagerObj := Mobile.Device('iPhone').ApplicationManager;
  // Retrieve application info from the device
  appObj := appManagerObj.GetApplicationByBundleId('com.example.myapp');

  // Verify whether the application is found
  if not appObj = nill then
    begin
    // Display the application information
    Log.Message('The application name is: ' + appObj.BundleName);
    Log.Message('The application display name is: ' + appObj.BundleDisplayName);
    Log.Message('The package path is: ' + appObj.Path);
    end
  else
    // Install the application
    appObj := appManagerObj.InstallApplication('C:\Work\MyApp.ipa');

  end;

C++Script, C#Script

function Test()
{
  var appManagerObj = Mobile["Device"]("iPhone")["ApplicationManager"];
  // Retrieve application info from the device
  var appObj = appManagerObj["GetApplicationByBundleId"]("com.example.myapp");

  // Verify whether the application is found
  if (appObj != null)
    {
    // Display the application information
    Log["Message"]("The application name is: " + appObj["BundleName"]);
    Log["Message"]("The application display name is: " + appObj["BundleDisplayName"]);
    Log["Message"]("The package path is: " + appObj["Path"]);
    }
  else
    // Install the application
    appObj = appManagerObj["InstallApplication"]("C:\\Work\\MyApp.ipa");

}

See Also

ApplicationManager Object (Legacy Mobile Testing)
Deploying iOS Applications to Devices (Legacy)

Highlight search results