Installing Packages on Devices (Legacy)

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.

If your tests require that a lot of applications be installed on the device, you may run out of disk space and memory. To avoid possible issues, you can install applications before testing and delete them from the device after the test completes.

This topic describes how you can install a package that resides on your hard drive to the specified Android device.

Installing Packages Automatically On Application Start

You can add your Android application package (.apk) files to the Tested Applications collection in your project and command TestComplete to install packages automatically when you launch the applications from the TestComplete IDE or from tests. To do this:

The application will be installed every time you launch it from the TestComplete IDE (for example, via the Run Selected or Run All commands of the TestedApps editor’s context menu) or from tests (for example, when you call the TestedApps.AndroidAppName.Run scripting method or the Run TestedApp operation). For more information on how to start tested Android applications, see Starting Tested Android Applications (Legacy).

Notes:

Installing Packages From Keyword Tests

To install a package from keyword tests, use the Install Package operation. Note that you need to previously specify the device where to install the package using the Select Device or Device Loop operation.

The operation has the following parameters:

  • PackageFullPath - the path to the package (.apk) to be installed to the device.

  • GrantPermissions - specifies whether all permissions listed in the application manifest will be enabled automatically after the application installation.

For more information, see the description of the operation.

To delete an application from the device, use the RemovePackage scripting method. To call the method from keyword tests, use the Call Object Method or Run Code Snippet keyword test operation. For more information on how to do this, see the operation's description.

Installing Packages From Scripts

To install the needed application from a package, use the InstallPackage method of the PackageManager object.

The sample code below demonstrates how to install an application from the specified package to the current device and automatically grant all required permissions after the application installation:

JavaScript, JScript

...
var PackObj = Mobile.Device().PackageManager.GetPackageFromAPK("D:\\Work\\MyPackage.apk");
Mobile.Device().PackageManager.InstallPackage(PackObj, true);
...

Python

...
PackObj = Mobile.Device().PackageManager.GetPackageFromAPK("D:\\Work\\MyPackage.apk");
Mobile.Device().PackageManager.InstallPackage(PackObj, True);
...

VBScript

...
Set PackObj = Mobile.Device.PackageManager.GetPackageFromAPK("D:\Work\MyPackage.apk")
Call Mobile.Device.PackageManager.InstallPackage(PackObj, True)
...

DelphiScript

...
var PackObj := Mobile.Device.PackageManager.GetPackageFromAPK('D:\Work\MyPackage.apk');
Mobile.Device.PackageManager.InstallPackage(PackObj, true);
...

C++Script, C#Script

...
var PackObj = Mobile["Device"]["PackageManager"]["GetPackageFromAPK"]("D:\\Work\\MyPackage.apk");
Mobile["Device"]["PackageManager"]["InstallPackage"](PackObj, true);
...

After the application is installed, you may need to run default activity in it. For a detailed description of how to do this from your scripts or keyword tests, see Starting Tested Android Applications (Legacy).

To remove the application after the test is over, use the RemovePackage method. For detailed information, see the method's description.

See Also

Working With Tested Android Applications (Legacy)
Install Package Operation
InstallPackage Method

Highlight search results