WaitForControlWithText Method

Applies to TestComplete 15.47, last modified on January 20, 2023

Description

Use this method to pause the script execution until a control with the specified text becomes available.

Declaration

AndroidProcessObj.WaitForControlWithText(Text, WaitTimeout)

AndroidProcessObj An expression, variable or parameter that specifies a reference to an AndroidProcess object
Text [in]    Required    String    
WaitTimeout [in]    Optional    Integer Default value: -1   
Result Boolean

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

Text

The caption of a control to wait for before continuing the test execution.

The caption can contain asterisk (*) or question mark (?) wildcards. The asterisk corresponds to a string of any length (including an empty string), the question mark corresponds to any single character (including none).

WaitTimeout

The number of milliseconds to wait until a control with the specified text becomes available. If Timeout is 0, the method returns immediately. If Timeout is -1, the waiting time is infinite.

Result Value

If a control with the specified text has been found, the method returns True; otherwise, it returns False.

Remarks

This method is fast enough to detect toast notifications which are displayed only for a short period of time.

If wildcards are not used, the sought for text must be specified exactly as it is displayed in the application (including the letter case and punctuation characters).

Example

The code below demonstrates how to delay the test execution until a notification with "Toast Example" text is displayed. If a control with the specified text is not found until the timeout elapses, TestComplete posts a warning to the test log.

JavaScript, JScript

function Test1()
{
  Mobile.SetCurrent("MyDevice");
  TestedApps.MyAndroidApp.Run();
  var appObj = Mobile.Device().Process("smartbear.example.demoapp");
  appObj.RootLayout("").Button("buttonToast").TouchButton();
    // Waits until a Toast notification displays the specified text
  if (appObj.WaitForControlWithText("Toast Example", 3000))
    // Posts an image with the notification
    Log.Picture(appObj.RootLayout("").Picture(), "Toast was displayed.");
  else 
    // Posts a warning to the test log
    Log.Warning("Toast was not displayed.");
}

Python

def Test1():
    Mobile.SetCurrent("MyDevice")
    TestedApps.MyAndroidApp.Run()
    appObj = Mobile.Device().Process("smartbear.example.demoapp")
    appObj.RootLayout("").Button("buttonToast").TouchButton()
    # Waits until a Toast notification displays the specified text
    if appObj.WaitForControlWithText("Toast Example", 3000):
        # Posts an image with the notification
        Log.Picture(appObj.RootLayout("").Picture(), "Toast was displayed.")
    else:
        # Posts a warning to the test log
        Log.Warning("Toast was not displayed.")

VBScript

Sub Test1()
  Dim appObj
  Call Mobile.SetCurrent("MyDevice")
  Call TestedApps.MyAndroidApp.Run
  Set appObj = Mobile.Device.Process("smartbear.example.demoapp")
  Call appObj.RootLayout("").Button("buttonToast").TouchButton
  ' Waits until a Toast notification displays the specified text
  If appObj.WaitForControlWithText("Toast Example", 3000) Then
    ' Posts an image with the notification
    Call Log.Picture(appObj.RootLayout("").Picture, "Toast was displayed.")
  Else
    ' Posts a warning to the test log.
    Call Log.Warning("Toast was not displayed.")
  End If
End Sub

DelphiScript

procedure Test1;
var appObj;
begin
  Mobile.SetCurrent('MyDevice');
  TestedApps.MyAndroidApp.Run;
  appObj := Mobile.Device.Process('smartbear.example.demoapp');
  appObj.RootLayout('').Button('buttonToast').TouchButton;
  // Waits until a Toast notification displays the specified text
  if appObj.WaitForControlWithText('Toast Example', 3000) then
    // Posts an image with the notification
    Log.Picture(appObj.RootLayout('').Picture, 'Toast was displayed.')
  else
    // Posts a warning to the test log
    Log.Warning('Toast was not displayed.');
end;

C++Script, C#Script

function Test1()
{
  Mobile["SetCurrent"]("MyDevice");
  TestedApps["MyAndroidApp"]["Run"]();
  var appObj = Mobile["Device"]["Process"]("smartbear.example.demoapp");
  appObj["RootLayout"]("")["Button"]("buttonToast")["TouchButton"]();
  // Waits until a Toast notification displays the specified text
  if (appObj["WaitForControlWithText"]("Toast Example", 3000))
    // Posts an image with the notification
    Log["Picture"](appObj["RootLayout"]("")["Picture"](), "Toast was displayed.");
  else
    // Posts a warning to the test log
    Log["Warning"]("Toast was not displayed.");
}

See Also

AndroidProcess Object
Waiting for Toast Notifications in Android Open Applications (Legacy)
Testing Android Applications (Legacy)

Highlight search results