WaitForState Method

Applies to TestComplete 14.70, last modified on April 22, 2021

Description

The WaitForState method delays script execution until the task reaches the specified state, unless the specified time limit is reached first.

Declaration

TaskObj.WaitForState(StateWaitTime)

TaskObj An expression, variable or parameter that specifies a reference to a Task object
State [in]    Required    Integer    
WaitTime [in]    Optional    Integer Default value: 0   
Result Boolean

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

State

Specifies the task’s state to be waited for. Read the Network Suite States topic to learn about available task states.

WaitTime

Sets the time limit in milliseconds. 0 means indefinite time limit.

Result Value

True if the expected state is reached, and False otherwise.

Remarks

Use the Task.State property to check the task’s state.

Example

The following script halts the task’s execution if it does not stop on its own for a specified period.

JavaScript, JScript

function Test()
{
  var Task = NetworkSuite.Jobs.ItemByName("Job1").Tasks.ItemByName("Task1");
  ...
  if (! Task.WaitForState(ns_Idle, 600000))
    Task.Stop();
}

Python

def Test():
  Task = NetworkSuite.Jobs.ItemByName["Job1"].Tasks.ItemByName["Task1"]
  # ...
  if not Task.WaitForState(ns_Idle, 600000):
    Task.Stop()

VBScript

Sub Test
  Set Task = NetworkSuite.Jobs.ItemByName("Job1").Tasks.ItemByName("Task1")
  ...
  If Not Task.WaitForState(ns_Idle, 600000) Then
    Task.Stop
  End If
End Sub

DelphiScript

procedure Test;
var Task;
begin
  Task := NetworkSuite.Jobs.ItemByName['Job1'].Tasks.ItemByName['Task1'];
  ...
  if not Task.WaitForState(ns_Idle, 600000) then
    Task.Stop;
end;

C++Script, C#Script

function Test()
{
  var Task = NetworkSuite["Jobs"]["ItemByName"]("Job1")["Tasks"]["ItemByName"]("Task1");
  ...
  if (! Task["WaitForState"](ns_Idle, 600000))
    Task["Stop"]();
}

See Also

Distributed Testing
Stop Method
Run Method
State Property
OnNetTaskStateChange Event

Highlight search results