AddNew Method

Applies to TestComplete 15.31, last modified on March 17, 2022
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 Hosts.AddNew method lets you create a new item in the host collection represented by the Hosts object.

Declaration

HostsObj.AddNew()

HostsObj An expression, variable or parameter that specifies a reference to a Hosts object
Result A Host object

Applies To

The method is applied to the following object:

Result Value

A Host object for the newly created item of the host collection.

Example

The code below creates a new host, specifies properties for it (name, address, user name, and so on) and then checks whether the created host can be used by a network suite.

JavaScript, JScript

function HostObj()
{
  // Creates a new host
  var Host = NetworkSuite.Hosts.AddNew();
  // Specifies the host's parameters
  Host.Name = "Host1";
  Host.Address = "TEST-W764";
  Host.Domain = "EDGS";
  Host.UserName = "tester";
  Host.Password = "123";
  
  // Verifies whether the created host can be used by a network suite
  if (Host.Verify)
    Log.Message("The host properties are valid.")
  else
    Log.Warning("The host properties aren't valid.");
}

Python

def HostObj():
  # Creates a new host 
  Host = NetworkSuite.Hosts.AddNew()
  # Specifies the host's parameters 
  Host.Name = "Host1"
  Host.Address = "TEST-W764"
  Host.Domain = "EDGS"
  Host.UserName = "tester"
  Host.Password = "123"
  # Verifies whether the created host can be used by a network suite 
  if Host.Verify:
    Log.Message("The host properties are valid.")
  else: 
     Log.Warning("The host properties aren't valid.")

VBScript

Sub HostObj

  ' Creates a new host
  Set Host = NetworkSuite.Hosts.AddNew
  ' Specifies the host's parameters
  Host.Name = "Host1"
  Host.Address = "TEST-W764"
  Host.Domain = "EDGS"
  Host.UserName = "tester"
  Host.Password = "123"
  
  ' Verifies whether the created host can be used by a network suite
  If Host.Verify Then
    Log.Message("The host properties are valid.")
  Else
    Log.Warning("The host properties aren't valid.")
  End If
  
End Sub

DelphiScript

function HostObj;
var Host;
begin

  // Creates a new host
  Host := NetworkSuite.Hosts.AddNew;
  // Specifies the host's parameters
  Host.Name := 'Host1';
  Host.Address := 'TEST-W764';
  Host.Domain := 'EDGS';
  Host.UserName := 'tester';
  Host.Password := '123';
  
  // Verifies whether the created host can be used by a network suite
  if (Host.Verify) then
    Log.Message('The host properties are valid.')
  else
    Log.Warning('The host properties aren''t valid.');

end;

C++Script, C#Script

function HostObj()
{
  // Creates a new host
  var Host = NetworkSuite["Hosts"]["AddNew"]();
  // Specifies the host's parameters
  Host["Name"] = "Host1";
  Host["Address"] = "TEST-W764";
  Host["Domain"] = "EDGS";
  Host["UserName"] = "tester";
  Host["Password"] = "123";
  
  // Verifies whether the created host can be used by a network suite
  if ( Host["Verify"] )
    Log["Message"]( "The host properties are valid." )
  else
    Log["Warning"]( "The host properties aren't valid." );
}

See Also

Distributed Testing
Items Property
ItemByName Property
Count Property

Highlight search results