AddNew Method

Applies to TestComplete 15.67, last modified on August 29, 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 Tasks.AddNew method lets you create a new item in the task collection represented by the Tasks object.

Declaration

TasksObj.AddNew()

TasksObj An expression, variable or parameter that specifies a reference to a Tasks object
Result A Task object

Applies To

The method is applied to the following object:

Result Value

A Task object for the newly created item of the task collection.

Example

The following example demonstrates how to create a task in script.

JavaScript, JScript

function Test()
{

  var JobName, Tasks, NewTask;
  JobName = "Job1";
  // Obtains the tasks that belong to the specified job
  Tasks = NetworkSuite.Jobs.ItemByName(JobName).Tasks;
  // Creates a new task in the specified job
  NewTask = Tasks.AddNew();
  // Modifies the task’s properties
  NewTask.Host = NetworkSuite.Hosts.ItemByName("SlaveComputer1");
  NewTask.ProjectPath = "D:\\Network Suite\\Projects\\SampleProject.mds";
  NewTask.Test = "Slave_Script\\Script\\Slave_VB\\Main";
  // Runs the task
  NewTask.Run(true);

}

Python

def Test():
  JobName = "Job1";
  # Obtains the tasks that belong to the specified job
  Tasks = NetworkSuite.Jobs.ItemByName[JobName].Tasks
  # Creates a new task in the specified job
  NewTask = Tasks.AddNew()
  # Modifies the task's properties
  NewTask.Host = NetworkSuite.Hosts.ItemByName["SlaveComputer1"];
  NewTask.ProjectPath = "D:\\Network Suite\\Projects\\SampleProject.mds";
  NewTask.Test = "Slave_Script\\Script\\Slave_VB\\Main";
  # Runs the task
  NewTask.Run(True)

VBScript

Sub Test

  Dim JobName, Tasks, NewTask
  JobName = "Job1"
  ' Obtains the tasks that belong to the specified job
  Set Tasks = NetworkSuite.Jobs.ItemByName(JobName).Tasks
  ' Creates a new task in the specified job
  Set NewTask = Tasks.AddNew
  ' Modifies the task’s properties
  Set NewTask.Host = NetworkSuite.Hosts.ItemByName("SlaveComputer1")
  NewTask.ProjectPath = "D:\Network Suite\Projects\SampleProject.mds"
  NewTask.Test = "Slave_Script\Script\Slave_VB\Main"
  ' Runs the task
  NewTask.Run(True)

End Sub

DelphiScript

procedure Test();
var JobName, Tasks, NewTask;
begin

  JobName := 'Job1';
  // Obtains the tasks that belong to the specified job
  Tasks := NetworkSuite.Jobs.ItemByName(JobName).Tasks;
  // Creates a new task in the specified job
  NewTask := Tasks.AddNew();
  // Modifies the task’s properties
  NewTask.Host := NetworkSuite.Hosts.ItemByName('SlaveComputer1');
  NewTask.ProjectPath := 'D:\Network Suite\Projects\SampleProject.mds';
  NewTask.Test := 'Slave_Script\Script\Slave_VB\Main';
  // Runs the task
  NewTask.Run(true);

end;

C++Script, C#Script

function Test()
{

  var JobName, Tasks, NewTask;
  JobName = "Job1";
  // Obtains the tasks that belong to the specified job
  Tasks = NetworkSuite["Jobs"]["ItemByName"](JobName)["Tasks"];
  // Creates a new task in the specified job
  NewTask = Tasks["AddNew"]();
  // Modifies the task’s properties
  NewTask["Host"] = NetworkSuite["Hosts"]["ItemByName"]("SlaveComputer1");
  NewTask["ProjectPath"] = "D:\\Network Suite\\Projects\\SampleProject.mds";
  NewTask["Test"] = "Slave_Script\\Script\\Slave_VB\\Main";
  // Runs the task
  NewTask["Run"](true);

}
Note: In order for the task to run successfully, the project, specified in the script must reside on the slave host where it will be run before the task starts. For information on copying projects on slave hosts, see Copying Slave Projects to Remote Computers.

See Also

Distributed Testing
Items Property
ItemByName Property
Count Property

Highlight search results