Waiting for Object State in Android Open 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 may need to delay the test execution until an application object is in a specific state. For example, your test may need to wait until a control in the application is enabled before simulating user actions against it.

If your tested application is Open, TestComplete adds a number of custom properties and methods to objects that can help you determine an object’s state.

To delay your test execution until an object has a specific property value, use the WaitProperty method. TestComplete adds this method to all the tested objects. The method delays the test execution until the specified property of the object (it can be either a native property or a property added by TestComplete) takes the specified value or until the timeout elapses.

The code below demonstrates how to delay the test execution until a button in the tested mobile application is enabled:

JavaScript, JScript

function Test()
{

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

  var btn = Mobile.Device("MyDevice").Process("smartbear.example.demoapp").Layout("NO_ID").Button("btnClick");
  if (btn.WaitProperty("Enabled", true, 10000))
  {
    // The button is enabled
    // ...
  }
  else
  {
    // The button is disabled
    // ...
  }

}

Python

def Test():

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

  btn = Mobile.Device("MyDevice").Process("smartbear.example.demoapp").Layout("NO_ID").Button("btnClick");
  if (btn.WaitProperty("Enabled", True, 10000)):
    # The button is enabled
    # ...
  else:
    # The button is disabled
    # ...

VBScript

Sub Test

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

  Set btn = Mobile.Device("MyDevice").Process("smartbear.example.demoapp").Layout("NO_ID").Button("btnClick")
  If btn.WaitProperty("Enabled", true, 10000) Then
    ' The button is enabled
    ' ...
  Else
    ' The button is disabled
    ' ...
  End If

End Sub

DelphiScript

procedure Test();
var btn;
begin

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

  btn := Mobile.Device('MyDevice').Process('smartbear.example.demoapp').Layout('NO_ID').Button('btnClick');
  if btn.WaitProperty('Enabled', true, 10000) then
    begin
      // The button is enabled
      // ...
    end
  else
    begin
      // The button is disabled
      // ...
    end;

end;

C++Script, C#Script

function Test()
{

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

  var btn = Mobile["Device"]("MyDevice")["Process"]("smartbear.example.demoapp")["Layout"]("NO_ID")["Button"]("btnClick");
  if (btn["WaitProperty"]("Enabled", true, 10000))
  {
    // The button is enabled
    // ...
  }
  else
  {
    // The button is disabled
    // ...
  }

}

See Also

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

Highlight search results