|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:
Add the needed Android application package (.apk files) to the list of tested applications. For information on how to do this, see Adding Android Applications to the List of Tested Applications (Legacy).
Enable the Deploy to the device on start option in the Run-Mode Parameters section of the TestedApps editor.
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).
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
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:
var PackObj = Mobile.Device().PackageManager.GetPackageFromAPK("D:\\Work\\MyPackage.apk");
PackObj = Mobile.Device().PackageManager.GetPackageFromAPK("D:\\Work\\MyPackage.apk");
Set PackObj = Mobile.Device.PackageManager.GetPackageFromAPK("D:\Work\MyPackage.apk")
Call Mobile.Device.PackageManager.InstallPackage(PackObj, True)
var PackObj := Mobile.Device.PackageManager.GetPackageFromAPK('D:\Work\MyPackage.apk');
var PackObj = Mobile["Device"]["PackageManager"]["GetPackageFromAPK"]("D:\\Work\\MyPackage.apk");
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).