Name Property

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

Description

The Name property returns the unique name of the given task in the task collection of the particular job in the network suite (the Name property of the task). This name can be used to identify the task in this collection via the Tasks.ItemByName property.

Declaration

TaskObj.Name

Read-Only Property String
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

A string that represents the unique name the given task has in the task collection of the job.

Example

The following code snippet obtains the tasks that belong to the specified job by their index and posts their names to the test log.

JavaScript, JScript

function Test()
{

  var JobName, Tasks, Count, i, Task;
  // Specifies the name of the job
  JobName = "MyJob";
  // Obtains the tasks that belong to the specified job
  Tasks = NetworkSuite.Jobs.ItemByName(JobName).Tasks;
  // Determines how many tasks the job contains
  Count = Tasks.Count;
  if (Count > 0)
    {
    Log.AppendFolder("The job contains the following tasks:");
    // Iterates through the tasks
    for (i = 0; i <Count; i++)
      {
      // Obtains the task by its index
      Task = Tasks.Items(i);
      // Posts the task’s name to the test log
      Log.Message(Task.Name);
      }
    Log.PopLogFolder();
    }
}

Python

def Test():
  # Specifies the name of the job
  JobName = "MyJob"
  # Obtains the tasks that belong to the specified job
  Tasks = NetworkSuite.Jobs.ItemByName[JobName].Tasks
  # Determines how many tasks the job contains
  Count = Tasks.Count
  if Count > 0:
    Log.AppendFolder("The job contains the following tasks:")
    # Iterates through the tasks
    for i in range(0, Count):
      # Obtains the task by its index
      Task = Tasks.Items[i]
      # Posts the task's name to the test log
      Log.Message(Task.Name)
    Log.PopLogFolder()

VBScript

Sub Test

  Dim JobName, Tasks, Count, i, Task
  ' Specifies the name of the job
  JobName = "MyJob"
  ' Obtains the tasks that belong to the specified job
  Set Tasks = NetworkSuite.Jobs.ItemByName(JobName).Tasks
  ' Determines how many tasks the job contains
  Count = Tasks.Count
  If Count > 0 Then
    Log.AppendFolder("The job contains the following tasks:")
    ' Iterates through the tasks
    For i = 0 To Count - 1
      ' Obtains the task by its index
      Set Task = Tasks.Items(i)
      ' Posts the task’s name to the test log
      Log.Message(Task.Name)
    Next
    Log.PopLogFolder
  End If

End Sub

DelphiScript

procedure Test();
var JobName, Tasks, Count, i, Task;
begin

  // Specifies the name of the job
  JobName := 'MyJob';
  // Obtains the tasks that belong to the specified job
  Tasks := NetworkSuite.Jobs.ItemByName[JobName].Tasks;
  // Determines how many tasks the job contains
  Count := Tasks.Count;
  if Count > 0 then
    begin
    Log.AppendFolder('The job contains the following tasks:');
    // Iterates through the tasks
    for i := 0 to Count -1 do
      begin
      // Obtains the task by its index
      Task := Tasks.Items[i];
      // Posts the task’s name to the test log
      Log.Message(Task.Name);
      end;
    Log.PopLogFolder();
    end;
end;

C++Script, C#Script

function Test()
{

  var JobName, Tasks, Count, i, Task;
  // Specifies the name of the job
  JobName = "MyJob";
  // Obtains the tasks that belong to the specified job
  Tasks = NetworkSuite["Jobs"]["ItemByName"](JobName)["Tasks"];
  // Determines how many tasks the job contains
  Count = Tasks["Count"];
  if (Count > 0)
    {
    Log["AppendFolder"]("The job contains the following tasks:");
    // Iterates through the tasks
    for (i = 0; i <Count; i++)
      {
      // Obtains the task by its index
      Task = Tasks["Items"](i);
      // Posts the task’s name to the test log
      Log["Message"](Task["Name"]);
      }
    Log["PopLogFolder"]();
    }
}

See Also

Distributed Testing
Task.Index
Tasks Object
Tasks.ItemByName

Highlight search results