WaitForState Method

Applies to TestComplete 15.58, last modified on November 27, 2023
The Network Suite functionality is deprecated. We don’t recommend using it for distributed testing. Consider using a CI/CD system for managing distributed tests. See Migrating Distributed Tests to CI/CD Systems for details. In case you need to run web tests on multiple environments in parallel, you can also try using your project’s Execution Plan.


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


JobObj.WaitForState(State, WaitTime)

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

Applies To

The method is applied to the following object:


The method has the following parameters:


Specifies the job’s state to wait for. Read the Network Suite States topic to learn about available job states.


Sets the time limit in milliseconds. 0 means an infinite time limit.

Result Value

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


Use the Job.State property to simply check the job’s state.


The following script halts job execution if it does not stop at the specified time.

JavaScript, JScript

function Test()
  var Job = NetworkSuite.Jobs.ItemByName("Job1");
  if (! Job.WaitForState(ns_Idle, 600000))


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


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


procedure Test;
var Job;
  Job := NetworkSuite.Jobs.ItemByName['Job1'];
  if not Job.WaitForState(ns_Idle, 600000) then

C++Script, C#Script

function Test()
  var Job = NetworkSuite["Jobs"]["ItemByName"]("Job1");
  if (! Job["WaitForState"](ns_Idle, 600000))

See Also

Distributed Testing
Stop Method
Run Method
State Property
OnNetJobStateChange Event

Highlight search results