Index Property (Task Objects)

Applies to TestComplete 15.63, last modified on April 23, 2024
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 Index property returns the index (starting from 0) of the given task in the task collection of the specific job in the network suite (see Tasks Object). This index can be used to identify the task in this collection via the Tasks.Items property. To learn the number of tasks in this collection, use the Tasks.Count property.

Declaration

TaskObj.Index

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 denoting the zero-based index that the given task has in the task collection of the job.

Example

The following code snippet creates a new task, obtains its index and posts it to the test log.

JavaScript, JScript

function Test()
{

  var NewTask, TaskName, JobName, Indx;
  // Specifies the name of the job
  JobName = "MyJob";
  // Creates a new task
  NewTask = NetworkSuite.Jobs.ItemByName(JobName).Tasks.AddNew();
  // Obtains the name of the created task
  TaskName = NewTask.Name;
  // Obtains the index of the created task
  Indx = NewTask.Index;
  // Posts the name and index of the created task to the test log
  Log.Message("A new " + TaskName + " task with the " + Indx + " index has been added to the " + JobName + " job");
  …

}

Python

def Test():
  # Specifies the name of the job
  JobName = "MyJob"
  # Creates a new task
  NewTask = NetworkSuite.Jobs.ItemByName[JobName].Tasks.AddNew()
  # Obtains the name of the created task
  TaskName = NewTask.Name
  # Obtains the index of the created task
  Indx = NewTask.Index
  # Posts the name and index of the created task to the test log
  Log.Message("A new " + TaskName + " task with the " + str(Indx) + " index has been added to the " + JobName + " job")

VBScript

Sub Test

  Dim NewTask, TaskName, JobName, Indx
  ' Specifies the name of the job
  JobName = "MyJob"
  ' Creates a new task
  Set NewTask = NetworkSuite.Jobs.ItemByName(JobName).Tasks.AddNew
  ' Obtains the name of the created task
  TaskName = NewTask.Name
  ' Obtains the index of the created task
  Indx = NewTask.Index
  ' Posts the name and index of the created task to the test log
  Log.Message("A new " & TaskName & " task with the " & Indx & " index has been added to the " & JobName & " job")
  …

End Sub

DelphiScript

procedure Test();
var NewTask, TaskName, JobName, Indx;
begin

  // Specifies the name of the job
  JobName := 'MyJob';
  // Creates a new task
  NewTask := NetworkSuite.Jobs.ItemByName[JobName].Tasks.AddNew;
  // Obtains the name of the created task
  TaskName := NewTask.Name;
  // Obtains the index of the created task
  Indx := NewTask.Index;
  // Posts the name and index of the created task to the test log
  Log.Message('A new ' + TaskName + ' task with the ' + aqConvert.IntToStr(Indx) + ' index has been added to the ' + JobName + ' job');
  …

end;

C++Script, C#Script

function Test()
{

  var NewTask, TaskName, JobName, Indx;
  // Specifies the name of the job
  JobName = "MyJob";
  // Creates a new task
  NewTask = NetworkSuite["Jobs"]["ItemByName"](JobName)["Tasks"]["AddNew"]();
  // Obtains the name of the created task
  TaskName = NewTask["Name"];
  // Obtains the index of the created task
  Indx = NewTask["Index"];
  // Posts the name and index of the created task to the test log
  Log["Message"]("A new " + TaskName + " task with the " + Indx + " index has been added to the " + JobName + " job");
  …

}

See Also

Distributed Testing
Task.Name
Tasks Object
Tasks.Count
Tasks.Items

Highlight search results