AndroidDevice Object

Applies to TestComplete 14.72, last modified on April 22, 2021

Description

The AndroidDevice object provides access to the specified Android device (a real device or a virtual machine). You can use this object to obtain information about the device and perform certain testing actions over it.

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 following example demonstrates how to obtain an Android device connected to your computer and simulate user actions on it:

JavaScript, JScript

function Test()
{

  // Specify the current device
  Mobile.SetCurrent("MyDevice");

  // Install an application on the device from the specified location on the computer
  var PackObj = Mobile.Device().PackageManager.GetPackageFromAPK("C:\\Android\\Apps\\MyApp\\bin\\myapp.apk");
  Mobile.Device().PackageManager.InstallPackage(PackObj);
  Mobile.Device().PackageManager.LaunchPackage(PackObj);

  // Perform testing actions
  …
  // Remove the application
  Mobile.Device().PackageManager.RemovePackage(PackObj);

}

Python

def Test():
  # Specify the current device
  Mobile.SetCurrent("MyDevice")

  # Install an application on the device from the specified location on the computer
  PackObj = Mobile.Device().PackageManager.GetPackageFromAPK("C:\\Android\\Apps\\MyApp\\bin\\myapp.apk")
  Mobile.Device().PackageManager.InstallPackage(PackObj)
  Mobile.Device().PackageManager.LaunchPackage(PackObj)

  # Perform testing actions
  # ...
  # Remove the application
  Mobile.Device().PackageManager.RemovePackage(PackObj);

VBScript

Sub Test
  ' Specify the current device
  Call Mobile.SetCurrent("MyDevice")

  ' Install an application on the device from the specified location on the computer
  Set PackObj = Mobile.Device.PackageManager.GetPackageFromAPK("C:\Android\Apps\MyApp\bin\myapp.apk")
  Call Mobile.Device.PackageManager.InstallPackage (PackObj)
  Call Mobile.Device.PackageManager.LaunchPackage (PackObj)

  ' Perform testing actions
  …
  ' Remove the application
  Call Mobile.Device.PackageManager.RemovePackage (PackObj)

End Sub

DelphiScript

procedure Test();
var PackObj;
begin

  // Specify the current device
  Mobile.SetCurrent('MyDevice');

  // Install an application on the device from the specified location on the computer
  PackObj := Mobile.Device.PackageManager.GetPackageFromAPK('C:\Android\Apps\MyApp\bin\myapp.apk');
  Mobile.Device.PackageManager.InstallPackage(PackObj);
  Mobile.Device.PackageManager.LaunchPackage(PackObj);

  // Perform testing actions
  …
  // Remove the application
  Mobile.Device.PackageManager.RemovePackage(PackObj);

end;

C++Script, C#Script

function Test()
{

  // Specify the current device
  Mobile["SetCurrent"]("MyDevice");

  // Install an application on the device from the specified location on the computer
  var PackObj = Mobile["Device"]["PackageManager"]["GetPackageFromAPK"]("C:\\Android\\Apps\\MyApp\\bin\\myapp.apk");
  Mobile["Device"]["PackageManager"]["InstallPackage"](PackObj);
  Mobile["Device"]["PackageManager"]["LaunchPackage"](PackObj);

  // Perform testing actions
  …
  // Remove the application
  Mobile["Device"]["PackageManager"]["RemovePackage"](PackObj);

}

See Also

Testing Android Applications
Device Method

Highlight search results