ItemByName Property

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

Description

The Items property returns a task specified by its name in the task collection represented by the Tasks object.

Declaration

TasksObj.ItemByName(Name)

Read-Only Property A Task object
TasksObj An expression, variable or parameter that specifies a reference to a Tasks object
Name [in]    Required    String    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

Name

The unique name of the desired task in the task collection.

Property Value

A Task object.

Remarks

If you use Python or DelphiScript, you should enclose the parameter of the ItemByName property in square brackets: ItemByName[Name].

Example

The following code snippet obtains a task by its name and runs it.

JavaScript, JScript

function Test()
{

  var JobName, Tasks, TaskName, Task;
  // Specifies the name of the job to which the task belongs
  JobName = "Job1";
  // Specifies the name of the needed task
  TaskName = "Task1";
  // Obtains the tasks that belong to the specified job
  Tasks = NetworkSuite.Jobs.ItemByName(JobName).Tasks;
  // Obtains the task by its name
  Task = Tasks.ItemByName(TaskName);
  Task.Run(true);

}

Python

def Test():
  # Specifies the name of the job to which the task belongs
  JobName = "Job1"
  # Specifies the name of the needed task
  TaskName = "Task1"
  # Obtains the tasks that belong to the specified job
  Tasks = NetworkSuite.Jobs.ItemByName[JobName].Tasks
  # Obtains the task by its name
  Task = Tasks.ItemByName[TaskName];
  Task.Run(True);

VBScript

Sub Test

  Dim JobName, Tasks, TaskName, Task
  ' Specifies the name of the job to which the task belongs
  JobName = "Job1"
  ' Specifies the name of the needed task
  TaskName = "Task1"
  ' Obtains the tasks that belong to the specified job
  Set Tasks = NetworkSuite.Jobs.ItemByName(JobName).Tasks
  ' Obtains the task by its name
  Set Task = Tasks.ItemByName(TaskName)
  Task.Run(True)

End Sub

DelphiScript

procedure Test();
var JobName, Tasks, TaskName, Task;
begin

  // Specifies the name of the job to which the task belongs
  JobName := 'Job1';
  // Specifies the name of the needed task
  TaskName := 'Task1';
  // Obtains the tasks that belong to the specified job
  Tasks := NetworkSuite.Jobs.ItemByName[JobName].Tasks;
  // Obtains the task by its name
  Task: = Tasks.ItemByName[TaskName];
  Task.Run(true);

end;

C++Script, C#Script

function Test()
{

  var JobName, Tasks, TaskName, Task;
  // Specifies the name of the job to which the task belongs
  JobName = "Job1";
  // Specifies the name of the needed task
  TaskName = "Task1";
  // Obtains the tasks that belong to the specified job
  Tasks = NetworkSuite["Jobs"]["ItemByName"](JobName)["Tasks"];
  // Obtains the task by its name
  Task = Tasks["ItemByName"](TaskName);
  Task["Run"](true);

}

See Also

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

Highlight search results