slPacker.Pack Method

Applies to TestComplete 15.42, last modified on September 08, 2022

Description

The slPacker.Pack method compresses certain files, for example, files of test results, etc. The method can compress not only listed files, but also all files existing in the listed folders and their subfolders.

The Script configuration option specifies the archiving configuration that defines which archiving program will be used for compression and how the archiver will do this. Whether the folder tree information will be preserved in the archive depends upon the parameters you set for the archiver via the chosen archiving configuration.

Note that to use the WinZip archiver from TestComplete, the WinZip Command Line Support Add-On plugin should be installed in WinZip. You can download this add-on from http://www.winzip.com/prodpagecl.htm.

Declaration

slPacker.Pack(FileList, ArchiveRootPath, ArchivePath)

FileList [in]    Required    String    
ArchiveRootPath [in]    Required    String    
ArchivePath [in]    Required    String    
Result Boolean

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

FileList

A list of names for the desired files and folders, in which individual file and folder names are separated by the (0Dh, 0Ah) characters. This list can be built manually or by using the slPacker.GetFileListFromFolder method.

ArchiveRootPath

The path to the folder that contains the listed files and folders.

ArchivePath

The fully qualified path to the resulting archive file. If the file extension is omitted, the file will be given the default extension used in archives of the archiving program defined in the archiving configuration that is set by the Script configuration option.

Result Value

True if the files are compressed successfully, and False otherwise.

Remarks

During a test run, TestComplete keeps test results in memory. So, the results folder will hold all the results only when the test run is over. If you need to archive the results of the current test run using the Pack method, you should command TestComplete to save them before packing. To save the results, use the Log.SaveResultsAs method. For example, the following code saves test results to a collection of HTML, XML, XSL files including a number of helper files:

JavaScript, JScript

Log.SaveResultsAs(Project.ConfigPath + "Log\\Tmp.tcLog", 1);

Python

Log.SaveResultsAs(Project.ConfigPath + "Log\\Tmp.tcLog", 1)

VBScript

Log.SaveResultsAs Project.ConfigPath + "Log\Tmp.tcLog", 1

DelphiScript

Log.SaveResultsAs(Project.ConfigPath + 'Log\Tmp.tcLog', 1);

C++Script, C#Script

Log["SaveResultsAs"](Project["ConfigPath"] + "Log\\Tmp.tcLog", 1);

When creating a test that calls the Pack method, do not place the resulting archive in the same folder where the files you will pack are stored. Otherwise, during the next test run, an error will occur if the name of the resulting archive coincides with the name of one of the files you will pack.

Example

The following script exports results to an MHT file and then compresses the exported data.

JavaScript, JScript

function PackResults()
{

  var workDir = Project.ConfigPath + "Log\\ExportedResults\\";
  var packedResults = Project.ConfigPath + "Log\\PackedResults\\";

  // Clears the previous results
  aqFileSystem.DeleteFolder(workDir, true);
  aqFileSystem.DeleteFolder(packedResults, true);

  aqFileSystem.CreateFolder(packedResults);
  aqFileSystem.CreateFolder(workDir);

  // Exports the results
  var fileName = workDir + "MyFile.mht";
  Log.SaveResultsAs(fileName, 2);

  // Gets the list of files to pack
  fileList = slPacker.GetFileListFromFolder(workDir);

  // Specifies the name of the archive
  var archivePath = packedResults + "CompressedResults";

  // Packes the resutls
  if (slPacker.Pack(fileList, workDir, archivePath))
    Log.Message("Files compressed successfully.");

}

Python

def PackResults():

  workDir = Project.ConfigPath + "Log\\ExportedResults\\"
  packedResults = Project.ConfigPath + "Log\\PackedResults\\"

  # Clears the previous results
  aqFileSystem.DeleteFolder(workDir, True)
  aqFileSystem.DeleteFolder(packedResults, True)

  aqFileSystem.CreateFolder(packedResults)
  aqFileSystem.CreateFolder(workDir)

  # Exports the results
  fileName = workDir + "MyFile.mht"
  Log.SaveResultsAs(fileName, 2)

  # Gets the list of files to pack
  fileList = slPacker.GetFileListFromFolder(workDir)

  # Specifies the name of the archive
  archivePath = packedResults + "CompressedResults"

  # Packes the resutls
  if (slPacker.Pack(fileList, workDir, archivePath)):
    Log.Message("Files compressed successfully.")

VBScript

Sub PackResults

  workDir = Project.ConfigPath + "Log\ExportedResults\"
  packedResults = Project.ConfigPath + "Log\PackedResults\"

  ' Clears the previous results
  Call aqFileSystem.DeleteFolder(workDir, True)
  Call aqFileSystem.DeleteFolder(packedResults, True)
  aqFileSystem.CreateFolder(packedResults)
  aqFileSystem.CreateFolder(workDir)

  ' Exports the results
  fileName = workDir + "MyFile.mht"
  Call Log.SaveResultsAs(fileName, 2)

  ' Gets the list of files to pack
  fileList = slPacker.GetFileListFromFolder(workDir)

  ' Specifies the name of the archive
  archivePath = packedResults + "CompressedResults"

  ' Packes the resutls
  If slPacker.Pack(fileList, workDir, archivePath) Then
    Log.Message "Files compressed successfully."
  End If

End Sub

DelphiScript

procedure PackResults();
var workDir, packedResults, fileName, fileList, archivePath;
begin

  workDir := Project.ConfigPath + 'Log\ExportedResults\';
  packedResults := Project.ConfigPath + 'Log\PackedResults\';

  // Clears the previous results
  aqFileSystem.DeleteFolder(workDir, true);
  aqFileSystem.DeleteFolder(packedResults, true);

  aqFileSystem.CreateFolder(packedResults);
  aqFileSystem.CreateFolder(workDir);

  // Exports the results
  fileName := workDir + 'MyFile.mht';
  Log.SaveResultsAs(fileName, 2);

  // Gets the list of files to pack
  fileList := slPacker.GetFileListFromFolder(workDir);

  // Specifies the name of the archive
  archivePath := packedResults + 'CompressedResults';

  // Packes the resutls
  if slPacker.Pack(fileList, workDir, archivePath) then
    Log.Message('Files compressed successfully.');

end;

C++Script, C#Script

function PackResults()
{

  var workDir = Project["ConfigPath"] + "Log\\ExportedResults\\";
  var packedResults = Project["ConfigPath"] + "Log\\PackedResults\\";

  // Clears the previous results
  aqFileSystem["DeleteFolder"](workDir, true);
  aqFileSystem["DeleteFolder"](packedResults, true);

  aqFileSystem["CreateFolder"](packedResults);
  aqFileSystem["CreateFolder"](workDir);

  // Exports the results
  var fileName = workDir + "MyFile.mht";
  Log["SaveResultsAs"](fileName, 2);

  // Gets the list of files to pack
  fileList = slPacker["GetFileListFromFolder"](workDir);

  // Specifies the name of the archive
  var archivePath = packedResults + "CompressedResults";

  // Packes the resutls
  if (slPacker["Pack"](fileList, workDir, archivePath))
    Log["Message"]("Files compressed successfully.");

}

See Also

GetFileListFromFolder Method
PackCurrentTest Method
Packer Options Dialog

Highlight search results