Contains Method

Applies to TestComplete 15.44, last modified on November 10, 2022

Description

The Contains method lets you find out whether the item with the specified name belongs to the Files, Objects or Regions collection.

Declaration

ProgObj.Contains(Name)

ProgObj An expression, variable or parameter that specifies a reference to one of the objects listed in the Applies To section
Name [in]    Required    String    
Result Boolean

Applies To

The method is applied to the following objects:

Parameters

The method has the following parameter:

Name

Unique name of the collection item whose presence in the collection you want to check.

Result Value

True if the given item is part of the collection and False otherwise.

Example

The following example demonstrates how to add a file to the Stores > Files collection using the Files.Add method. The code checks whether the file is already in the collection, and if it is not there, adds the file to it.

JavaScript, JScript

function StoreFile()
{
  var FileName = "C:\\MyFile.txt";
  var StoredItemName = "MyFile";

  // Verify that StoredItemName is not taken
  if (Files.Contains(StoredItemName))
  {
    Log.Message ("The Files collection already contains this file.");
    return;
  }

  // Add the file to the Files collection
  if (Files.Add(FileName, StoredItemName))
    Log.Message("The file has been successfully saved in Stores.");
  else
    Log.Message (Files.LastError);
}

Python

def StoreFile():
  FileName = "C:\\MyFile.txt"
  StoredItemName = "MyFile"
  # Verify that StoredItemName is not taken
  if Files.Contains(StoredItemName):
    Log.Message ("The Files collection already contains this file.");
    return
  # Add the file to the Files collection
  if Files.Add(FileName, StoredItemName):
    Log.Message("The file has been successfully saved in Stores.")
  else:
     Log.Message (Files.LastError)

VBScript

Sub StoreFile
  Dim FileName, StoredItemName

  FileName = "C:\MyFile.txt"
  StoredItemName = "MyFile"

  ' Verify that StoredItemName is not taken
  If Files.Contains(StoredItemName) Then
    Log.Message ("The Files collection already contains this file.")
  End If

  ' Add the file to the Files collection
  If Files.Add(FileName, StoredItemName) Then
    Log.Message ("The file has been successfully saved in Stores.")
  Else
    Log.Message (Files.LastError)
  End If
End Sub

DelphiScript

procedure StoreFile;
var FileName, StoredItemName;
begin
  FileName := 'C:\MyFile.txt';
  StoredItemName := 'MyFile';

  // Verify that StoredItemName is not taken
  if Files.Contains(StoredItemName) then
    Log.Message ('The Files collection already contains this file.');

  // Add the file to the Files collection
  if Files.Add(FileName, StoredItemName) then
    Log.Message('The file has been successfully saved in Stores.')
  else
    Log.Message (Files.LastError);
end;

C++Script, C#Script

function StoreFile()
{
  var FileName = "C:\\MyFile.txt";
  var StoredItemName = "MyFile";

  // Verify that StoredItemName is not taken
  if (Files["Contains"](StoredItemName))
  {
    Log["Message"]("The Files collection already contains this file");
    return;
  }

  // Add the file to the Files collection
  if (Files["Add"](FileName, StoredItemName))
    Log["Message"]("The file has been successfully saved in Stores.");
  else
    Log["Message"](Files["LastError"]);
}

See Also

Count Method
ContainsFile Method

Highlight search results