InstallPackage Method

Applies to TestComplete 15.45, last modified on December 01, 2022
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

Installs the package specified as the method’s parameter on the device. Additionally, this method allows you to automatically give all permissions the application needs by using the GrantPermissions parameter.

Declaration

PackageManagerObj.InstallPackage(Package, GrantPermissions)

PackageManagerObj An expression, variable or parameter that specifies a reference to a PackageManager object
Package [in]    Required    The PackageObject object.    
GrantPermissions [in]    Optional    Boolean Default value: False   
Result Boolean

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

Package

Specifies the PackageObject object that corresponds to the package to be installed.

GrantPermissions

Specifies whether the permissions the application needs will be enabled automatically or manually. Possible values are:

Value Description
False Default. No permissions will be enabled automatically, but you can manually allow the desired permissions after the application requests them.
True All required permissions listed in the application manifest will be enabled automatically after the installation.

Result Value

Returns True, if the application package has been successfully installed, and False otherwise.

Example

The code below obtains the PackageObject object that corresponds to the specified package file (*.apk), installs this package on the device, launches the default activity for the package and then removes the package from the device:

JavaScript, JScript

function Test()
{
  // Obtain the PackageObject object
  var DeviceObj = Mobile.Device("VirtualBox");
  var PackManagerObj = DeviceObj.PackageManager;
  var PackObj = PackManagerObj.GetPackageFromAPK("C:\\Work\\MyPackage.apk");
  // Install the package
  PackManagerObj.InstallPackage(PackObj);
  // Launch the default activity for the package
  PackManagerObj.LaunchPackage(PackObj);
  // Remove the package
  PackManagerObj.RemovePackage(PackObj);
}

Python

def Test():
  # Obtain the PackageObject object
  DeviceObj = Mobile.Device("VirtualBox")
  PackManagerObj = DeviceObj.PackageManager
  PackObj = PackManagerObj.GetPackageFromAPK("C:\\Work\\MyPackage.apk")
  # Install the package
  PackManagerObj.InstallPackage(PackObj)
  # Launch the default activity for the package
  PackManagerObj.LaunchPackage(PackObj)
  # Remove the package
  PackManagerObj.RemovePackage(PackObj)

VBScript

Sub Test
  ' Obtain the PackageObject object
  Set DeviceObj = Mobile.Device("VirtualBox")
  Set PackManagerObj = DeviceObj.PackageManager
  Set PackObj = PackManagerObj.GetPackageFromAPK("C:\Work\MyPackage.apk")
  ' Install the package
  PackManagerObj.InstallPackage(PackObj)
  ' Launch the default activity for the package
  PackManagerObj.LaunchPackage(PackObj)
  ' Remove the package
  PackManagerObj.RemovePackage(PackObj)
End Sub

DelphiScript

function Test;
var DeviceObj, PackManagerObj, PackObj: OleVariant;
begin
  // Obtain the PackageObject object
  DeviceObj := Mobile.Device('VirtualBox');
  PackManagerObj := DeviceObj.PackageManager;
  PackObj := PackManagerObj.GetPackageFromAPK('C:\Work\MyPackage.apk');
  // Install the package
  PackManagerObj.InstallPackage(PackObj);
  // Launch the default activity for the package
  PackManagerObj.LaunchPackage(PackObj);
  // Remove the package
  PackManagerObj.RemovePackage(PackObj);
end;

C++Script, C#Script

function Test()
{
  // Obtain the PackageObject object
  var DeviceObj = Mobile["Device"]("VirtualBox");
  var PackManagerObj = DeviceObj["PackageManager"];
  var PackObj = PackManagerObj["GetPackageFromAPK"]("C:\\Work\\MyPackage.apk");
  // Install the package
  PackManagerObj["InstallPackage"](PackObj);
  // Launch the default activity for the package
  PackManagerObj["LaunchPackage"](PackObj);
  // Remove the package
  PackManagerObj["RemovePackage"](PackObj);
}

See Also

RemovePackage Method
LaunchPackage Method
PackageManager Object
Installing Packages on Devices (Legacy)

Highlight search results