IsActivePackage Method

Applies to TestComplete 15.47, last modified on January 20, 2023
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

Checks if a package is currently active on the device.

Declaration

PackageManagerObj.IsActivePackage(Package)

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

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Package

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

Result Value

Returns True if the specified package is currently active, and False otherwise.

Remarks

The application is considered active as long as it is running. Most Android applications go into the background when you press the back or home button, so an application will be considered active unless you close it. You can close an application in the following way:

  • Launch the recent applications menu

    The way you open this menu varies on different devices. Usually, you need to long press the home button, or tap the menu button.

  • Swipe the required application so that it disappears.

    On most devices, you swipe up or right-swipe to do this.

This should close most applications.

If your application is still considered active, execute the Device.ShellExecute("am force-stop <package_name>") command from scripts.

Example

The code below checks if the specified package is currently active on the device and posts an informative message to the test log:

JavaScript, JScript

function CheckPackage()
{

var pack = Mobile.Device("VirtualBox").PackageManager.InstalledPackage(0);
if (Mobile.Device("VirtualBox").PackageManager.IsActivePackage(pack))
  Log.Message("The specified package is active.")
else
  Log.Message("The specified package is not active.")

}

Python

def CheckPackage():
  pack = Mobile.Device("VirtualBox").PackageManager.InstalledPackage(0)
  if (Mobile.Device("VirtualBox").PackageManager.IsActivePackage(pack)):
    Log.Message("The specified package is active.")
  else:
    Log.Message("The specified package is not active.")

VBScript

Sub CheckPackage

Set pack = Mobile.Device("VirtualBox").PackageManager.InstalledPackage(0)
If Mobile.Device("VirtualBox").PackageManager.IsActivePackage(pack) Then
  Log.Message "The specified package is active."
Else
  Log.Message "The specified package is not active."
End If

End Sub

DelphiScript

procedure CheckPackage();
var pack;
begin

pack := Mobile.Device('VirtualBox').PackageManager.InstalledPackage(0);
if (Mobile.Device('VirtualBox').PackageManager.IsActivePackage(pack)) then
  Log.Message('The specified package is active.')
else
  Log.Message('The specified package is not active.')
end;

C++Script, C#Script

function CheckPackage()
{

var pack = Mobile["Device"]("VirtualBox")["PackageManager"]["InstalledPackage"](0);
if (Mobile["Device"]("VirtualBox")["PackageManager"]["IsActivePackage"](pack))
  Log["Message"]("The specified package is active.")
else
  Log["Message"]("The specified package is not active.")

}

See Also

LaunchPackage Method
InstallPackage Method
PackageManager Object

Highlight search results