Description
The File
method copies the specified file to the folder holding test results and then posts an informative message ( ) with the link to the copied file in the test log. The name of the copied file is displayed in the Link column of the Test Log panel.
This can be useful in the following situation: suppose your application generates a file with a customer list, which you save to the Files collection for future comparison. If during a test run it is revealed that the customer list is incorrect in the generated file, you can save the file to the test log.
Declaration
Log.File(FileName, MessageText, Details, Priority, Attr, FolderID)
FileName | [in] | Required | String | |
MessageText | [in] | Optional | Variant | Default value: Empty string |
Details | [in] | Optional | Variant | Default value: Empty string |
Priority | [in] | Optional | Integer | Default value: pmNormal |
Attr | [in] | Optional | A LogAttributes object |
Default value: Default attributes |
FolderID | [in] | Optional | Integer | Default value: -1 |
Result | String |
Applies To
The method is applied to the following object:
Parameters
The method has the following parameters:
FileName
The fully qualified path to the file to be posted to the test log. Note that TestComplete renames the file when posting it to the log (see the Remarks section below).
Note: | You can specify the desired fully-qualified path manually or you can specify the name of an environment variable that stores this path. For this purpose, use the Log.File("%ProgramFiles%\SmartBear\TestComplete 14\EULA.rtf", "Some Text", , , , ) syntax. |
MessageText
Message text. This text will be added to the Message column of the Test Log. MessageText can hold data of any OLE-compatible type. If it cannot be converted to text, its value is ignored.
The parameter does not support multiline text, that is, you cannot post multiline messages to the Message column. To post multiline text to your test log, use the AdditionalInformation parameter.Details
Additional text to be displayed in the Details pane of the Test Log. Details can hold data of any type compatible with OLE. If it cannot be converted to text, its value is ignored.
The Details parameter can also hold HTML code. The test engine will compile the HTML page and display it in the Details pane. For more information, see Posting Messages to the Log.
Priority
Message priority. You can use any integer number or any of the following constants:
Constant | Value | Description |
---|---|---|
pmLowest |
100 | The lowest priority of the message. |
pmLower |
200 | The message priority which is lower than normal. |
pmNormal |
300 | The normal (default) priority of the message. |
pmHigher |
400 | The message priority which is higher than normal. |
pmHighest |
500 | The highest priority of the message. |
Attr
The font and color settings that will be applied to the newly created file message in the log. They are represented by a LogAttributes
object. If this parameter is omitted, default attributes will be applied.
FolderID
Identifier of the folder in the test log to which the message will be posted. To get this identifier, use the CreateFolder
or AppendFolder
method. If this parameter refers to a non-existent folder, is omitted or is set to -1 (the default value), the File
method will either post the message to the default folder of the test log or append it to the test log outside of any folder (if the default folder is not set). The default folder is the folder that is currently at the top of the folder stack, which is populated during the script run. To push a folder to or pop it out of this stack, use the PushLogFolder
or the PopLogFolder
method correspondingly.
Result Value
The full path to the file saved in the results folder.
Remarks
-
The method renames the file when copying it to the test results folder. The new name has the format
File<index>.originalExtension
. This approach helps TestComplete avoid naming conflicts when posting files. Below is a typical example of the code that might cause conflicts:Log.File("C:\MyFile.txt");
ChangeFileInSomeWay("C:\MyFile.txt");
Log.File("C:\MyFile.txt");If TestComplete does not rename the file when posting it to the log, the second call to the
Log.File
method would cause a naming conflict. -
If the
Log.CallStackSettings.EnableStackOnFile
orLog.CallStackSettings.EnableStackOnLink
property is True, then the test engine collects information about the execution sequence of tests that led to the call of theLog.File
method and displays this information in the Call Stack page of the test log. See Collecting Call Stack Information for Log Messages. -
When you call the
Log.File
method, the test engine generates theOnLogFile
event.
Example
The code below writes some data to a file during test execution and then posts this file to the test log.
JavaScript, JScript
function PostingFileExample()
{
// Specifies the path to a file
var sPath = "C:\\Work\\TestData.txt";
// Writes some data to the file
aqFile.WriteToTextFile(sPath, "Test data", aqFile.ctANSI);
// Posts the file to the test log
Log.File(sPath, "A file with test data.");
}
Python
def PostingFileExample():
# Specifies the path to a file
sPath = "C:\\MyFiles\\MyFile.txt"
# Writes some data to the file
aqFile.WriteToTextFile(sPath, "Test data", aqFile.ctANSI)
# Posts the file to the test log
Log.File(sPath, "A file with test data.")
VBScript
Sub PostingFileExample()
' Specifies the path to a file
sPath = "C:\Work\TestData.txt"
' Writes some data to the file
Call aqFile.WriteToTextFile(sPath, "Test data", aqFile.ctANSI)
' Posts the file to the test log
Call Log.File(sPath, "A file with test data.")
End Sub
DelphiScript
function PostingFileExample;
var sPath;
begin
// Specifies the path to a file
sPath := 'C:\Work\TestData.txt';
// Writes some data to the file
aqFile.WriteToTextFile(sPath, 'Test data', aqFile.ctANSI);
// Posts the file to the test log
Log.File(sPath, 'A file with test data.');
end;
C++Script, C#Script
function PostingFileExample()
{
// Specifies the path to a file
var sPath = "C:\\Work\\TestData.txt";
// Writes some data to the file
aqFile["WriteToTextFile"]( sPath, "Test data", aqFile["ctANSI"] );
// Posts the file to the test log
Log["File"](sPath, "A file with test data." );
}
See Also
Test Results
Posting Files to the Log
FileCount Property
Error Method
Message Method
Warning Method
Event Method
Checkpoint Method
Picture Method
Link Method
OnLogFile Event
LogAttributes Object