State Property

Applies to TestComplete 15.45, last modified on December 01, 2022
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.

Description

The State property returns the state of the given task.

Declaration

TaskObj.State

Read-Only Property Integer
TaskObj An expression, variable or parameter that specifies a reference to a Task object

Applies To

The property is applied to the following object:

Property Value

An integer value that stands for the task state. Read the Network Suite States topic to learn about available task states.

Remarks

To delay script execution until the task reaches a specific state, use the Task.WaitForState method.

Example

The following code is a handler for the OnNetSuiteStateChange event occurring every time the network suite’s task changes its state. The code posts the task’s state to the test log.

JavaScript, JScript

// Handler of the event that occurs each time the task state changes
function GeneralEvents_OnNetTaskStateChange(Sender, Task)
{
  // Posts the task’s state to the test log
  Log.Message("The " + Task.Name + " task state = " + aqConvert.IntToStr(Task.State))
}

Python

# Handler of the event that occurs each time the task state changes
def GeneralEvents_OnNetTaskStateChange():
  Task = NetworkSuite.Jobs.Items[0].Tasks.ItemByName["MyTask"]
  Log.Message("The " + Task.Name + " task state = " + aqConvert.IntToStr(Task.State))

VBScript

' Handler of the event that occurs each time the task state changes
Sub GeneralEvents_OnNetTaskStateChange(Sender, Task)
  ' Posts the task’s state to the test log
  Log.Message("The " & Task.Name & " task state = " & aqConvert.IntToStr(Task.State))
End Sub

DelphiScript

// Handler of the event that occurs each time the task state changes
procedure GeneralEvents_OnNetTaskStateChange(Sender, Task);
begin
  // Posts the task’s state to the test log
  Log.Message('The ' + Task.Name + ' task state = ' + aqConvert.IntToStr(Task.State))
end;

C++Script, C#Script

// Handler of the event that occurs each time the task state changes
function GeneralEvents_OnNetTaskStateChange(Sender, Task)
{
  // Posts the task’s state to the test log
  Log["Message"]("The " + Task["Name"] + " task state = " + aqConvert["IntToStr"](Task["State"]))
}

See Also

Distributed Testing
Task.WaitForState

Highlight search results