Waiting for Objects in Image-Based Tests

Applies to TestComplete 15.62, last modified on March 14, 2024

When testing an application, you may need to delay the test run until the needed object in your tested application becomes available (for example, appears on the screen).

Using Auto-Wait Timeouts

When simulating user actions in image-based tests, TestComplete searches for the image of the target control on the screen. By default, it waits for the sought-for image to appear during a period specified by the Auto-wait timeout option.

Configure the Auto-wait timeout value to control the time it takes for TestComplete to wait for images:

Image-Based Testing: Configuring the Auto-wait timeout property

Click the image to enlarge it.

In your keyword tests, you can also specify a custom timeout for individual operations that simulate image-based actions:

Image-Based Testing: Configuring the operation's timeout

Click the image to enlarge it.

See Specifying Custom Timeouts For Operations.

Waiting for Object Image

To delay the test execution until the control’s or screen area’s image appears on the screen:

  1. Use the ImageSetItem.Exists method to check whether the screen shows the expected image.

    As an alternative, in mobile tests, you can use mobile checkpoints to check whether your mobile device screen shows the expected image. In desktop and web tests, you can use region checkpoints.

  2. Call the method in a loop until it passes.

Note: Since constantly calling image comparison can slow down the test performance, you can add a delay to the loop to avoid it.

The code below shows how to delay the test run until the needed object appears on the screen:

JavaScript, JScript

function Test()
{

  Mobile.SetCurrent("MyDevice");

  // ...

  // Delays the test execution until the Orders activity appears on the device screen
  while (! ImageRepository.orders.Orders_Form.Exists())
    Delay(500);

  // ...

}

Python

def Test():

  Mobile.SetCurrent("MyDevice");

  # ...
  
  # Delays the test execution until the Orders activity appears on the device screen
  while not ImageRepository.orders.Orders_Form.Exists():
    Delay(500);

  # ...

VBScript

Sub Test

  Mobile.SetCurrent("MyDevice")

  ' ...

  ' Delays the test execution until the Orders activity appears on the device screen
  While Not ImageRepository.orders.Orders_Form.Exists
    Delay(500)
  Wend

  ' ...

End Sub

DelphiScript

procedure Test();
begin

  Mobile.SetCurrent('MyDevice');

  // ...

  // Delays the test execution until the Orders activity appears on the device screen
  while not ImageRepository.orders.Orders_Form.Exists() do
    Delay(500);

  // ...

end;

C++Script, C#Script

function Test()
{

  Mobile["SetCurrent"]("MyDevice");

  // ...

  // Delays the test execution until the Orders activity appears on the device screen
  while (! ImageRepository["orders"]["Orders_Form"]["Exists"]())
    Delay(500);

  // ...

}

See Also

Checking Object State
Image-Based Testing
Common Tasks
Mobile Checkpoints
Region Checkpoints

Highlight search results