Installing Packages on Devices

Applies to TestComplete 14.0, last modified on January 23, 2019

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.

If the application is already installed to the device, TestComplete will delete and re-install it. To prevent losing some user-specific data when reinstalling the application, enable the Keep the data and cache directories on removal option.

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 parameter:

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

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:

JavaScript, JScript

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

Python

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

VBScript

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

DelphiScript

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

C++Script, C#Script

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

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.

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
Install Package Operation
InstallPackage Method

Highlight search results