PackageObject Object

Applies to TestComplete 14.30, last modified on November 21, 2019

Description

The PackageObject object corresponds to an Android application package. You can use this object to install and launch the default activity for a package or remove a package. For this purpose, pass it as a parameter to the InstallPackage, LaunchPackage and RemovePackage methods respectively.

The PackageObject object is returned by the GetPackageFromAPK and GetInstalledPackageByName methods and by the InstalledPackage property of the PackageManager object.

In order for TestComplete to be able to provide access to an Android device, the device should be connected to Android Debug Bridge.

Members

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

GetPackageFromAPK Method
GetInstalledPackageByName Method
InstalledPackage Property
InstallPackage Method
RemovePackage Method

Highlight search results