State Property

Applies to TestComplete 12.60, last modified on September 17, 2018

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