ItemByName Property

Applies to TestComplete 15.47, last modified on January 20, 2023
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 Items property returns a job specified by the name it has in the job collection represented by the Jobs object.

Declaration

JobsObj.ItemByName(Name)

Read-Only Property A Job object
JobsObj An expression, variable or parameter that specifies a reference to a Jobs 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 job in the job collection.

Property Value

A Job object.

Remarks

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

Example

The code below obtains the specified job by its name and then posts the names of all the tasks that belong to this job to the test log.

JavaScript, JScript

function JobByNameExample()
{
  // Specifies the name of a job
  var jName = "Job_Name";
  // Obtains information about the job
  var Job = NetworkSuite.Jobs.ItemByName(jName);
  // Obtains the tasks that belong to the job
  var Tasks = Job.Tasks;
  // Obtains the number of the tasks
  var Num = Tasks.Count;
  
  // Iterates through the tasks
  for (var i = 0; i < Num; i++)
  {
    // Obtains the current item
    var Task = Tasks.Items(i);
    var Name = Task.Name;
    // Posts the task's name to the test log
    Log.Message(Name);
  }
}

Python

def JobByNameExample():
  # Specifies the name of a job
  jName = "Job_Name"
  # Obtains information about the job
  Job = NetworkSuite.Jobs.ItemByName[jName]
  # Obtains the tasks that belong to the job
  Tasks = Job.Tasks
  # Obtains the number of the tasks
  Num = Tasks.Count
  # Iterates through the tasks
  for i in range(0, Num):
    # Obtains the current item
    Task = Tasks.Items[i]
    Name = Task.Name
    # Posts the task's name to the test log
    Log.Message(Name)

VBScript

Sub JobByNameExample()

  ' Specifies the name of a job
  jName = "Job_Name"
  ' Obtains information about the job
  Set Job = NetworkSuite.Jobs.ItemByName(jName)
  ' Obtains the tasks that belong to the job
  Set Tasks = Job.Tasks
  ' Obtains the number of the tasks
  Num = Tasks.Count
  
  ' Iterates through the tasks
  For i = 0 to (Num - 1)
    ' Obtains the current item
    Set Task = Tasks.Items(i)
    Name = Task.Name
    ' Posts the task's name to the test log
    Log.Message(Name)
  Next
     
End Sub

DelphiScript

function JobByNameExample;
var jName, Job, Tasks, Num, i, Task, Name;
begin

  // Specifies the name of a job
  jName := 'Job_Name';
  // Obtains information about the job
  Job := NetworkSuite.Jobs.ItemByName[jName];
  // Obtains the tasks that belong to the job
  Tasks := Job.Tasks;
  // Obtains the number of the tasks
  Num := Tasks.Count;
  
  // Iterates through the tasks
  for i := 0 to (Num - 1) do
  begin
    // Obtains the current item
    Task := Tasks.Items[i];
    Name := Task.Name;
    // Posts the task's name to the test log
    Log.Message(Name);
  end;

end;

C++Script, C#Script

function JobByNameExample()
{
  // Specifies the name of a job
  var jName = "Job_Name";
  // Obtains information about the job
  var Job = NetworkSuite["Jobs"]["ItemByName"](jName);
  // Obtains the tasks that belong to the job
  var Tasks = Job["Tasks"];
  // Obtains the number of the tasks
  var Num = Tasks["Count"];
  
  // Iterates through the tasks
  for (var i = 0; i < Num; i++)
  {
    // Obtains the current item
    var Task = Tasks["Items"](i);
    var Name = Task["Name"];
    // Posts the task's name to the test log
    Log["Message"](Name);
  }
}

See Also

Distributed Testing
Count Property
Items Property
Job Object
Name Property

Highlight search results