Waiting for Activities in Android Open Applications (Legacy)

Applies to TestComplete 15.40, last modified on July 05, 2022
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.

When testing mobile applications, you may need to delay the test execution until a certain activity becomes active in the tested Android application.

If your tested application is Open, TestComplete adds a number of custom properties and methods to test objects. To wait for a certain activity, use the specific WaitActivity method. TestComplete adds this method to the Device.Process objects that correspond to tested Android applications. The method delays the test execution until the activity becomes active or until the specified timeout elapses.

The code below demonstrates how to delay the test execution until the specified activity in the tested mobile application becomes active. If the specified activity is not found until the timeout elapses, TestComplete posts an informative message to the test log.

JavaScript, JScript

function Test()
{
  Mobile.SetCurrent("MyDevice");
  var appObj = Mobile.Device("MyDevice").Process("com.example.orders");

  // Waits until the specified activity becomes available in the tested application
  if (appObj.WaitActivity("MainActivity", 300))
  // Perform testing actions
  // ...
  else 
  // Posts a message to the test log
    Log.Message("MainActivity is not found.");
}

Python

def Test():
  Mobile.SetCurrent("MyDevice");
  appObj = Mobile.Device("MyDevice").Process("com.example.orders");

  # Waits until the specified activity becomes available in the tested application
  if (appObj.WaitActivity("MainActivity", 300)):
  # Perform testing actions
  # ...
  else:
  # Posts a message to the test log
    Log.Message("MainActivity is not found.");

VBScript

Sub Test
  Mobile.SetCurrent("MyDevice")
  Set appObj = Mobile.Device("MyDevice").Process("com.example.orders")

  ' Waits until the specified activity becomes available in the tested application
  If appObj.WaitActivity("MainActivity", 300) Then 
  ' Perform testing actions
  ' ...
  Else 
  ' Posts a message to the test log
    Log.Message "MainActivity is not found."
  End If 
End Sub 

DelphiScript

procedure Test();
var appObj;
begin
  Mobile.SetCurrent('MyDevice');
  appObj := Mobile.Device('MyDevice').Process('com.example.orders');

  // Waits until the specified activity becomes available in the tested application
  if (appObj.WaitActivity('MainActivity', 300)) then
  // Perform testing actions
  // ...
  else 
  // Posts a message to the test log
    Log.Message('MainActivity is not found.');
end;

C++Script, C#Script

function Test()
{
  Mobile["SetCurrent"]("MyDevice");
  var appObj = Mobile["Device"]("MyDevice")["Process"]("com.example.orders");

  // Waits until the specified activity becomes available in the tested application
  if (appObj["WaitActivity"]("MainActivity", 300))
  // Perform testing actions
  // ...
  else 
  // Posts a message to the test log
    Log["Message"]("MainActivity is not found.");
}

See Also

WaitActivity Method
Checking Object State (Legacy)
Testing Android Applications (Legacy)
Testing Android Applications (Legacy)

Highlight search results