Waiting for Objects in iOS Applications (Legacy)

Applies to TestComplete 15.47, last modified on January 20, 2023
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 iOS application.

Using Auto-Wait Timeouts

When simulating user actions against iOS 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 iOS 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()
{
  // Select the mobile device
  Mobile.SetCurrent("iPhone");
  // Run the tested application
  var parentObj = Mobile.Device().Process("SampleApp").Window(0);
  var childName = "Button(\"Simple Button\")";

  // 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():
  # Select the mobile device
  Mobile.SetCurrent("iPhone");
  # Run the tested application
  parentObj = Mobile.Device().Process("SampleApp").Window(0);
  childName = "Button(\"Simple Button\")";

  # 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()
  ' Select the mobile device
  Mobile.SetCurrent("iPhone")
  
  Set parentObj = Mobile.Device.Process("SampleApp").Window(0)
  childName = "Button(""Simple Button"")"

  ' 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
  // Select the mobile device
  Mobile.SetCurrent('iPhone');
  
  parentObj := Mobile.Device.Process('SampleApp').Window(0);
  childName := 'Button(''Simple Button'')';

  // 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()
{
  // Select the mobile device
  Mobile["SetCurrent"]("iPhone");
  // Run the tested application
  var parentObj = Mobile["Device"].Process("SampleApp")["Window"](0);
  var childName = "Button(\"Simple Button\")";

  // 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()
{
  // Select the mobile device
  Mobile.SetCurrent("iPhone");
  // Run the tested application
  Mobile.Device().ApplicationManager.RunApplication(SampleApp);
 
  // Waits until the SampleApp application process is loaded on the mobile device
  if (Mobile.Device().WaitProcess("SampleApp", 10000).Exists)
  {
    // The "SampleApp" process is running
    // Simulates user actions against the application
    // ...
  }
  
}

Python

def Test():
  # Select the mobile device
  Mobile.SetCurrent("iPhone");
  # Run the tested application
  Mobile.Device().ApplicationManager.RunApplication(SampleApp);
 
  # Waits until the SampleApp application process is loaded on the mobile device
  if (Mobile.Device().WaitProcess("SampleApp", 10000).Exists):
    # The "SampleApp" process is running
    # Simulates user actions against the application
    # ...

VBScript

Sub Test()
  ' Select the mobile device
  Mobile.SetCurrent("iPhone")
  
  ' Run the tested application
  Mobile.Device.ApplicationManager.RunApplication(SampleApp)
 
  ' Waits until the SampleApp application process is loaded on the mobile device
  If Mobile.Device.WaitProcess("SampleApp", 10000).Exists Then
    ' The "SampleApp" process is running
    ' Simulates user actions against the application
    ' ...
  End If
 
End Sub

DelphiScript

procedure Test();
begin
  // Select the mobile device
  Mobile.SetCurrent('iPhone');
  // Run the tested application
  Mobile.Device.ApplicationManager.RunApplication(SampleApp);
 
  // Waits until the SampleApp application process is loaded on the mobile device
  if Mobile.Device.WaitProcess('SampleApp', 10000).Exists then
    begin
      // The "SampleApp" process is running
      // Simulates user actions against the application
      // ...
    end;

end;

C++Script, C#Script

function Test()
{
  // Select the mobile device
  Mobile["SetCurrent"]("iPhone");
  // Run the tested application
  Mobile["Device"].ApplicationManager["RunApplication"](SampleApp);
 
  // Waits until the SampleApp application process is loaded on the mobile device
  if (Mobile["Device"].WaitProcess("SampleApp", 10000)["Exists"])
  {
    // The "SampleApp" process is running
    // Simulates user actions against the application
    // ...
  }
  
}

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

See Also

Simulating User Actions on iOS Applications (Legacy)
Testing iOS Applications (Legacy)
Specifying Custom Timeouts For Operations

Highlight search results