AddNew Method

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

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