Waiting for Activities in Android Open Applications

Applies to TestComplete 14.30, last modified on November 21, 2019

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
Testing Android Open Applications
Testing Android Applications

Highlight search results