Waiting for Objects in Android Open Applications (Legacy)

Applies to TestComplete 15.69, last modified on November 13, 2024
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 often need to delay the test execution until the needed object in your tested application becomes available. For example, you may need to wait until the application's form is loaded and displayed on the device's screen.

This topic explains how to delay the test execution until TestComplete can access the needed object in your Android Open Application.

Using Auto-Wait Timeouts

When simulating user actions against mobile applications, TestComplete waits for the target control for a period specified by the Auto-wait timeout option. You can modify the option to change the time TestComplete will wait for objects.

In your keyword tests, you can also specify a custom timeout for individual operations that simulate actions in your Android application. See Specifying Custom Timeouts For Operations.

Using WaitNNN Methods

To wait for tested objects in mobile applications in your tests, you can use the WaitChild, WaitNamedChild and WaitAliasChild methods that TestComplete adds to all tested objects. These methods delay the test execution until the object with the specified name, mapped name or alias appears on the list of the object’s child objects or until the timeout elapses. The methods’Timeout parameter specifies the waiting period.

JavaScript, JScript

function Test()
{

  Mobile.SetCurrent("MyDevice");
  // ...
  var parentObj = Mobile.Device("MyDevice").Process("smartbear.example.demoapp").Layout("NO_ID");
  var childName = "Button(\"addBtn\")";

  // Waits until the specified child object is available in the tested application
  if (parentObj.WaitChild(childName, 10000).Exists)
  {
    // Child object exists
    // ...
  }
  else
  {
    // Child object does not exist
    // ...
  }

}

Python

def Test():

  Mobile.SetCurrent("MyDevice");
  # ...
  parentObj = Mobile.Device("MyDevice").Process("smartbear.example.demoapp").Layout("NO_ID");
  childName = "Button(\"addBtn\")";

  # Waits until the specified child object is available in the tested application
  if (parentObj.WaitChild(childName, 10000).Exists):
    # Child object exists
    # ...
  else:
    # Child object does not exist
    # ...

VBScript

Sub Test

  Mobile.SetCurrent("MyDevice")
  …
  Set parentObj = Mobile.Device("MyDevice").Process("smartbear.example.demoapp").Layout("NO_ID")
  childName = "Button(""addBtn"")"

  ' Waits until the specified child object is available in the tested application
  If parentObj.WaitChild(childName, 10000).Exists Then
    ' Child object exists
    ' ...
  Else
    ' Child object does not exist
    ' ...
  End If

End Sub

DelphiScript

procedure Test();
var parentObj, childName;
begin

  Mobile.SetCurrent('MyDevice');
  …
  parentObj := Mobile.Device('MyDevice').Process('smartbear.example.demoapp').Layout('NO_ID');
  childName := 'Button(''addBtn'')';

  // Waits until the specified child object is available in the tested application
  if parentObj.WaitChild(childName, 10000).Exists then
    begin
      // Child object exists
      // ...
    end
  else
    begin
      // Child object does not exist
      // ...
    end;

end;

C++Script, C#Script

function Test()
{

  Mobile["SetCurrent"]("MyDevice");
  …
  var parentObj = Mobile["Device"]("MyDevice")["Process"]("smartbear.example.demoapp")["Layout"]("NO_ID");
  var childName = "Button(\"addBtn\")";

  // Waits until the specified child object is available in the tested application
  if (parentObj["WaitChild"](childName, 10000)["Exists"])
  {
    // Child object exists
    // ...
  }
  else
  {
    // Child object does not exist
    // ...
  }

}

For Device objects, TestComplete provides the WaitProcess method that delays the test execution until the specified process appears in the list of the device’s processes or until the timeout elapses.

JavaScript, JScript

function Test()
{

  Mobile.SetCurrent("MyDevice");
  ImageRepository.launcher.DemoApp.Touch();

  // Waits until the demoapp application process is loaded on the mobile device
  if (Mobile.Device("MyDevice").WaitProcess("smartbear.example.demoapp", 10000).Exists)
  {
    // The "demoapp" process is running
    // Simulates user actions against the application
    // ...
  }

}

Python

def Test():

  Mobile.SetCurrent("MyDevice");
  ImageRepository.launcher.DemoApp.Touch();

  # Waits until the demoapp application process is loaded on the mobile device
  if (Mobile.Device("MyDevice").WaitProcess("smartbear.example.demoapp", 10000).Exists):
    # The "demoapp" process is running
    # Simulates user actions against the application
    # ...

VBScript

Sub Test

  Mobile.SetCurrent("MyDevice")
  ImageRepository.launcher.DemoApp.Touch

  ' Waits until the demoapp application process is loaded on the mobile device
  If Mobile.Device("MyDevice").WaitProcess("smartbear.example.demoapp", 10000).Exists Then
    ' The "demoapp" process is running
    ' Simulates user actions against the application
    ' ...
  End If

End Sub

DelphiScript

procedure Test();
begin

  Mobile.SetCurrent('MyDevice');
  ImageRepository.launcher.DemoApp.Touch();

  // Waits until the demoapp application process is loaded on the mobile device
  if Mobile.Device('MyDevice').WaitProcess('smartbear.example.demoapp', 10000).Exists then
    begin
      // The "demoapp" process is running
      // Simulates user actions against the application
      // ...
    end;

end;

C++Script, C#Script

function Test()
{

  Mobile["SetCurrent"]("MyDevice");
  ImageRepository["launcher"]["DemoApp"]["Touch"]();

  // Waits until the demoapp application process is loaded on the mobile device
  if (Mobile["Device"]("MyDevice")["WaitProcess"]("smartbear.example.demoapp", 10000)["Exists"])
  {
    // The "demoapp" process is running
    // Simulates user actions against the application
    // ...
  }

}

For Device.Process objects, TestComplete provides the WaitForControlWithText method that delays the test execution until a control with the specified text becomes available or until the timeout elapses.

JavaScript, JScript

function Test()
{
  var process;
  var rootLayout;
  Mobile.SetCurrent("MyDevice");
  TestedApps.Orders.Run();
  process = Mobile.Device().Process("smartbear.example.orders");
  rootLayout = process.RootLayout("");
  rootLayout.ListView("listView1").TouchItem(3);
  rootLayout.Layout("buttons_layout").Button("deleteButton").TouchButton();
  // Waits until the confirmation is displayed
  if (process.WaitForControlWithText("Do you want to delete the selected order?", 300))
    // Performs testing actions
    process.RootLayout("", 2).Layout("content").Layout("buttonPanel").Layout("NO_ID").Button("button2").TouchButton();
  else
    // Posts a warning to the test log
    Log.Warning("Control was not found")
}

Python

def Test():
  Mobile.SetCurrent("MyDevice")
  TestedApps.Orders.Run()
  process = Mobile.Device().Process("smartbear.example.orders")
  rootLayout = process.RootLayout("")
  rootLayout.ListView("listView1").TouchItem(3)
  rootLayout.Layout("buttons_layout").Button("deleteButton").TouchButton()
  # Waits until the confirmation is displayed
  if process.WaitForControlWithText("Do you want to delete the selected order?", 300) :
    # Performs testing actions
    process.RootLayout("", 2).Layout("content").Layout("buttonPanel").Layout("NO_ID").Button("button2").TouchButton()
  else:
    # Posts a warning to the test log
    Log.Warning("Control was not found")

VBScript

Sub Test
  Dim process
  Dim rootLayout
  Call Mobile.SetCurrent("MyDevice")
  TestedApps.Orders.Run
  Set process = Mobile.Device.Process("smartbear.example.orders")
  Set rootLayout = process.RootLayout("")
  Call rootLayout.ListView("listView1").TouchItem(3)
  rootLayout.Layout("buttons_layout").Button("deleteButton").TouchButton
  ' Waits until the confirmation is displayed
  If process.WaitForControlWithText("Do you want to delete the selected order?", 300) Then
    ' Performs testing actions
    process.RootLayout("", 2).Layout("content").Layout("buttonPanel").Layout("NO_ID").Button("button2").TouchButton
  Else
    ' Posts a warning to the test log
    Log.Warning("Control was not found")
  End If
End Sub

DelphiScript

procedure Test;
  var process : OleVariant;
  var rootLayout : OleVariant;
begin
  Mobile.SetCurrent('MyDevice');
  TestedApps.Orders.Run;
  process := Mobile.Device.Process('smartbear.example.orders');
  rootLayout := process.RootLayout('');
  rootLayout.ListView('listView1').TouchItem(3);
  rootLayout.Layout('buttons_layout').Button('deleteButton').TouchButton;
  // Waits until the confirmation is displayed
  if (process.WaitForControlWithText('Do you want to delete the selected order?', 300)) then
    // Performs testing actions
    process.RootLayout('', 2).Layout('content').Layout('buttonPanel').Layout('NO_ID').Button('button2').TouchButton
  else
    // Posts a warning to the test log
    Log.Warning('Control was not found')
end;

C++Script, C#Script

function Test()
 {
   var process;
   var rootLayout;
   Mobile["SetCurrent"]("MyDevice");
   TestedApps["Orders"]["Run"]();
   process = Mobile["Device"]["Process"]("smartbear.example.orders");
   rootLayout = process["RootLayout"]("");
   rootLayout["ListView"]("listView1")["TouchItem"](3);
   rootLayout["Layout"]("buttons_layout")["Button"]("deleteButton")["TouchButton"]();
   // Waits until the confirmation is displayed
   if (process["WaitForControlWithText"]("Do you want to delete the selected order?", 300))
     // Performs testing actions
     process["RootLayout"]("", 2)["Layout"]("content")["Layout"]("buttonPanel")["Layout"]("NO_ID")["Button"]("button2")["TouchButton"]();
   else
     // Posts a warning to the test log
     Log["Warning"]("Control was not found")
 }

To call these methods in keyword tests, use the Call Object Method, Run Code Snippet or Run Script Routine operations.

See Also

Checking Object State (Legacy)
Testing Android Applications (Legacy)
Testing Android Applications (Legacy)
Specifying Custom Timeouts For Operations
Waiting for Objects in Image-Based Tests

Highlight search results