Count Property

Applies to TestComplete 15.70, last modified on December 17, 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 Count property returns the number of tasks in the task collection represented by the Tasks object.

Declaration

TasksObj.Count

Read-Only Property Integer
TasksObj An expression, variable or parameter that specifies a reference to a Tasks object

Applies To

The property is applied to the following object:

Property Value

An integer value that denotes the number of tasks in the task collection.

Example

The following code snippet obtains the tasks that belong to the specified network suite’s jobs and posts the tasks’ names to the test log.

JavaScript, JScript

function Test()
{

  var JobName, Tasks, Task, Count, i;
  // Specifies the name of a job
  JobName = "Job1";
  // Obtains the tasks that belong to the specified job
  Tasks = NetworkSuite.Jobs.ItemByName(JobName).Tasks;

  // Defines how many tasks the job contains
  Count = Tasks.Count;

  if (Count > 0)
    {
    Log.AppendFolder("The " + JobName + " job contains the following tasks:");
    for (i = 0; i < Count; i++)
      {
      // Obtains a task
      Task = Tasks.Items(i);
      // Posts the task's name to the test log
      Log.Message(Task.Name);
      }
    Log.PopLogFolder();
    }
  else
    Log.Message("The " + JobName + " job contains no tasks.");

}

Python

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

VBScript

Sub Test

  Dim JobName, Tasks, Task, Count, i
  ' Specifies the name of a job
  JobName = "Job1"
  ' Obtains the tasks that belong to the specified job
  Set Tasks = NetworkSuite.Jobs.ItemByName(JobName).Tasks

  ' Defines how many tasks the job contains
  Count = Tasks.Count

  If Count > 0 Then
    Log.AppendFolder("The " & JobName & " job contains the following tasks:")
    For i = 0 To Count - 1
      ' Obtains a task
      Set Task = Tasks.Items(i)
      ' Posts the task's name to the test log
      Log.Message(Task.Name)
    Next
    Log.PopLogFolder
  Else
    Log.Message("The " & JobName & " job contains no tasks.")
  End If

End Sub

DelphiScript

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

  // Specifies the name of a job
  JobName := 'Job1';
  // Obtains the tasks that belong to the specified job
  Tasks := NetworkSuite.Jobs.ItemByName(JobName).Tasks;

  // Defines how many tasks the job contains
  Count := Tasks.Count;

  if Count > 0 then
    begin
    Log.AppendFolder('The ' + JobName + ' job contains the following tasks:');
    for i := 0 to Count - 1 do
      begin
      // Obtains a task
      Task := Tasks.Items[i];
      // Posts the task's name to the test log
      Log.Message(Task.Name);
      end;
    Log.PopLogFolder();
    end
  else
    Log.Message('The ' + JobName + ' job contains no tasks.');

end;

C++Script, C#Script

function Test()
{

  var JobName, Tasks, Task, Count, i;
  // Specifies the name of a job
  JobName = "Job1";
  // Obtains the tasks that belong to the specified job
  Tasks = NetworkSuite["Jobs"]["ItemByName"](JobName)["Tasks"];

  // Defines how many tasks the job contains
  Count = Tasks["Count"];

  if (Count > 0)
    {
    Log["AppendFolder"]("The " + JobName + " job contains the following tasks:");
    for (i = 0; i < Count; i++)
      {
      // Obtains a task
      Task = Tasks["Items"](i);
      // Posts the task's name to the test log
      Log["Message"](Task["Name"]);
      }
    Log["PopLogFolder"]();
    }
  else
    Log["Message"]("The " + JobName + " job contains no tasks.");

}

See Also

Distributed Testing
Tasks.Items
Tasks.ItemByName

Highlight search results