TestedApps.AddAndroidApp Method

Applies to TestComplete 15.70, last modified on December 17, 2024

Description

The TestedApps.AddAndroidApp method adds the specified Android application package to the list of tested applications and returns the zero-based index of the application in the application list.

Declaration

TestedApps.AddAndroidApp(APKFileName)

APKFileName [in]    Required    String    
Result Integer

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

APKFileName

The fully-qualified path to the APK file stored on the local computer or in a shared network folder.

Result Value

The zero-based index of the application in the list of tested applications. You can use this index to access the corresponding AndroidTestedApp object using the TestedApps.Items(Index) property.

Example

The sample code below demonstrates how to add a new Android application to the list of tested applications, specify the application’s properties and run the application.

JavaScript, JScript

function AddAndroidApplication()
{

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

  // Adds the Android application from the package and obtains its index in the list of tested applications
  var ind = TestedApps.AddAndroidApp("C:\\Android\\apks\\SampleApp.apk");

  // Obtains the added tested application by its index and specifies its properties
  var AndroidTestedApp = TestedApps.Items(ind);
  AndroidTestedApp.DeployOnStart = true;
  AndroidTestedApp.Launch = true;
  AndroidTestedApp.GrantPermissions = true;
  AndroidTestedApp.KeepDataAndCache = false;
  
  // Checks if the applications is instrumented
  if (!AndroidTestedApp.Instrumented)
  {
    // Sets up custom certificate parameters
    AndroidTestedApp.UseCustomCertificate = true;
    AndroidTestedApp.KeystorePath = "C:\\Android\\Keystore";
    AndroidTestedApp.KeystorePassword = "KstrPass";
    AndroidTestedApp.Alias = "KeyAlias";
    AndroidTestedApp.KeyPassword = "KeyPass";
  }

  // Checks if TestComplete can work with the instrumented application
  if (AndroidTestedApp.InstrumentedWithSupportedVersion)
  {
    // Launches the application
    AndroidTestedApp.Run();
  }
  else
  {
    // Posts an error to the log
    Log.Error("Please use uninstrumented application or application instrumented for the current TestComplete version");
  }
}

Python

def AddAndroidApplication():
  # Sets the current device
  Mobile.SetCurrent("MyDevice")

  # Adds the Android application from the package and obtains its index in the list of tested applications
  ind = TestedApps.AddAndroidApp("C:\\Android\\apks\\SampleApp.apk")

  # Obtains the added tested application by its index and specifies its properties
  AndroidTestedApp = TestedApps.Items[ind]
  AndroidTestedApp.DeployOnStart = True
  AndroidTestedApp.Launch = True
  AndroidTestedApp.GrantPermissions = True
  AndroidTestedApp.KeepDataAndCache = False
   
  # Checks if the applications is instrumented
  if (not AndroidTestedApp.Instrumented):
    # Sets up custom certificate parameters
    AndroidTestedApp.UseCustomCertificate = True
    AndroidTestedApp.KeystorePath = "C:\\Android\\Keystore"
    AndroidTestedApp.KeystorePassword = "KstrPass"
    AndroidTestedApp.Alias = "KeyAlias"
    AndroidTestedApp.KeyPassword = "KeyPass"

  # Checks if TestComplete can work with the instrumented application
  if (AndroidTestedApp.InstrumentedWithSupportedVersion):
    # Launches the application
    AndroidTestedApp.Run()
  else:
   # Posts an error to the log
   Log.Error("Please use uninstrumented application or application instrumented for the current TestComplete version")

VBScript

Sub AddAndroidApplication

  ' Sets the current device
  Mobile.SetCurrent("MyDevice")

  ' Adds the Android application from the package and obtains its index in the list of tested applications
  ind = TestedApps.AddAndroidApp("C:\Android\apks\SampleApp.apk")

  ' Obtains the added tested application by its index and specifies its properties
  Set AndroidTestedApp = TestedApps.Items(ind)
  AndroidTestedApp.DeployOnStart = True
  AndroidTestedApp.Launch = True
  AndroidTestedApp.GrantPermissions = True
  AndroidTestedApp.KeepDataAndCache = False
  
  ' Checks if the applications is instrumented
  If not AndroidTestedApp.Instrumented Then
    ' Sets up custom certificate parameters
    AndroidTestedApp.UseCustomCertificate = true
    AndroidTestedApp.KeystorePath = "C:\Android\Keystore"
    AndroidTestedApp.KeystorePassword = "KstrPass"
    AndroidTestedApp.Alias = "KeyAlias"
    AndroidTestedApp.KeyPassword = "KeyPass"
  End If

  ' Checks if TestComplete can work with the instrumented application
  If AndroidTestedApp.InstrumentedWithSupportedVersion Then
    ' Launches the application
    AndroidTestedApp.Run()
  Else
    ' Posts an error to the log
    Log.Error("Please use uninstrumented application or application instrumented for the current TestComplete version")
  End If
End Sub

DelphiScript

procedure AddAndroidApplication();
var 
  ind, AndroidTestedApp;
begin

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

  // Adds the Android application from the package and obtains its index in the list of tested applications
  ind := TestedApps.AddAndroidApp('C:\Android\apks\SampleApp.apk');

  // Obtains the added tested application by its index and specifies its launch properties
  AndroidTestedApp := TestedApps.Items[ind];
  AndroidTestedApp.DeployOnStart := true;
  AndroidTestedApp.Launch := true;
  AndroidTestedApp.GrantPermissions := true;

  AndroidTestedApp.KeepDataAndCache := false;

  // Checks if the applications is instrumented
  if not AndroidTestedApp.Instrumented then
  begin
    // Sets up custom certificate parameters
    AndroidTestedApp.UseCustomCertificate := true;
    AndroidTestedApp.KeystorePath := 'C:\Android\Keystore';
    AndroidTestedApp.KeystorePassword := 'KstrPass';
    AndroidTestedApp.Alias := 'KeyAlias';
    AndroidTestedApp.KeyPassword := 'KeyPass';
  end;

  // Checks if TestComplete can work with the instrumented application
  if AndroidTestedApp.InstrumentedWithSupportedVersion then
    // Launches the application
    AndroidTestedApp.Run()
  else
    // Posts an error to the log
    Log.Error('Please use uninstrumented application or application instrumented for the current TestComplete version');
end;

C++Script, C#Script

function AddAndroidApplication()
{

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

  // Adds the Android application from the package and obtains its index in the list of tested applications
  var ind = TestedApps["AddAndroidApp"]("C:\\Android\\apks\\SampleApp.apk");

  // Obtains the added tested application by its index and specifies its properties
  var AndroidTestedApp = TestedApps["Items"](ind);
  AndroidTestedApp["DeployOnStart"] = true;
  AndroidTestedApp["Launch"] = true;
  AndroidTestedApp["GrantPermissions"] = true;
  AndroidTestedApp["KeepDataAndCache"] = false;
  
  // Checks if the applications is instrumented
  if (!AndroidTestedApp["Instrumented"])
  {
    // Sets up custom certificate parameters
    AndroidTestedApp["UseCustomCertificate"] = true;
    AndroidTestedApp["KeystorePath"] = "C:\\Android\\Keystore";
    AndroidTestedApp["KeystorePassword"] = "KstrPass";
    AndroidTestedApp["Alias"] = "KeyAlias";
    AndroidTestedApp["KeyPassword"] = "KeyPass";
  }

  // Checks if TestComplete can work with the instrumented application
  if (AndroidTestedApp["InstrumentedWithSupportedVersion"])
  {
    // Launches the application
    AndroidTestedApp["Run"]();
  }
  else
  {
    // Posts an error to the log
    Log["Error"]("Please use uninstrumented application or application instrumented for the current TestComplete version");
  }
}

See Also

TestedApps Object
AndroidTestedApp Object
Add Method
Adding Tested Applications

Highlight search results