Posting Images to the Log

Applies to TestComplete 15.69, last modified on November 13, 2024

You can post images to the test log by using specific keyword test operations and scripting methods. This topic describes how you can do this.

About

The test log can store images in BMP, JPEG, PNG, TIFF, GIF and ICO formats. You can specify the format for log images using the Image Settings dialog.

One of the ways to post images to the log is to use the same keyword test operations and scripting methods that are used to log error, warning, informative and other messages (see Posting Messages to the Log). In these cases, the posted images are optional for these messages, they serve as a complement to the posted text.

TestComplete includes specific keyword test operation (Post Screenshot) and scripting method (Log.Picture) that post messages of the image type, for which the image is a required parameter. These messages are displayed in the test log as informative messages () and have the icon in the Has Picture column.

Below is information about using keyword test operations and scripting methods. We will also give examples of posting images using message logging methods (Error, Warning and others) and the Log Message operation.

Posting Images From Scripts

You can post images to the log by using the Picture method of the Log object as well as by using methods that post error, warning, informative, event or checkpoint messages.

Using the Picture Method

The Picture method of the Log object has the following syntax:

Log.Picture(Picture, MessageText, AdditionalText, Priority, Attr, FolderID)

The first parameter, Picture, is a reference to the Picture object that represents an image to be posted, or the window or control whose image you would like to save to the log. For more information on naming windows and controls, see the Object Browser Naming Notation section. Other parameters of the method let you specify the message text, extended text, priority and message’s font and color attributes. For detailed information about them, see the method description.

The following example demonstrates how to use the Picture method. It posts the image of the active window or mobile device's desktop to the log:

Desktop

JavaScript, JScript

Log.Picture(Sys.Desktop.ActiveWindow(), "Message Text", "Extended Message Text", pmHighest);

Python

Log.Picture(Sys.Desktop.ActiveWindow(), "Message Text", "Extended Message Text", pmHighest)

VBScript

Log.Picture Sys.Desktop.ActiveWindow, "Message Text", "Extended Message Text", pmHighest

DelphiScript

Log.Picture(Sys.Desktop.ActiveWindow, 'Message Text', 'Extended Message Text', pmHighest);

C++Script, C#Script

Log["Picture"](Sys["Desktop"]["ActiveWindow"](), "Message Text", "Extended Message Text", pmHighest);

Web (Classic)

JavaScript, JScript

Log.Picture(Sys.Desktop.ActiveWindow(), "Message Text", "Extended Message Text", pmHighest);

Python

Log.Picture(Sys.Desktop.ActiveWindow(), "Message Text", "Extended Message Text", pmHighest)

VBScript

Log.Picture Sys.Desktop.ActiveWindow, "Message Text", "Extended Message Text", pmHighest

DelphiScript

Log.Picture(Sys.Desktop.ActiveWindow, 'Message Text', 'Extended Message Text', pmHighest);

C++Script, C#Script

Log["Picture"](Sys["Desktop"]["ActiveWindow"](), "Message Text", "Extended Message Text", pmHighest);

Mobile

JavaScript, JScript

Log.Picture(Mobile.Device("MyDevice").Desktop.Picture(), "Message Text", "Extended Message Text", pmHighest);

Python

Log.Picture(Mobile.Device("MyDevice").Desktop.Picture(), "Message Text", "Extended Message Text", pmHighest)

VBScript

Log.Picture Mobile.Device("MyDevice").Desktop.Picture, "Message Text", "Extended Message Text", pmHighest

DelphiScript

Log.Picture(Mobile.Device('MyDevice').Desktop.Picture(), 'Message Text', 'Extended Message Text', pmHighest);

C++Script, C#Script

Log["Picture"](Mobile["Device"]("MyDevice")["Desktop"].Picture(), "Message Text", "Extended Message Text", pmHighest);

Using the Error, Warning, Message, Event and Checkpoint Messages

You can use each of the following methods of the Log object to post images to the log:

All of these methods have the same parameter list:

Log.method(MessageText, AdditionalText, Priority, Attr, Picture, FolderID)

Here, method is a placeholder of the method’s name: Error, Warning, Message, Event or Checkpoint. The Picture parameter specifies a reference to the Picture object that represents an image to be posted, or the window or control whose image you would like to save to the log. This parameter is optional and you may omit it when calling these methods.

The following code demonstrates how to log a warning message along with the desktop image:

Desktop

JavaScript, JScript

Log.Warning("Warning Message Text", "Extended Text", pmHighest, null, Sys.Desktop);

Python

Log.Warning("Warning Message Text", "Extended Text", pmHighest, null, Sys.Desktop)

VBScript

Log.Warning "Warning Message Text", "Extended Text", pmHighest, Nothing, Sys.Desktop

DelphiScript

Log.Warning('Warning Message Text', 'Extended Text', pmHighest, nil, Sys.Desktop);

C++Script, C#Script

Log["Warning"]("Warning Message Text", "Extended Text", pmHighest, null, Sys["Desktop"]);

Web (Classic)

JavaScript, JScript

Log.Warning("Warning Message Text", "Extended Text", pmHighest, null, Sys.Desktop);

Python

Log.Warning("Warning Message Text", "Extended Text", pmHighest, null, Sys.Desktop)

VBScript

Log.Warning "Warning Message Text", "Extended Text", pmHighest, Nothing, Sys.Desktop

DelphiScript

Log.Warning('Warning Message Text', 'Extended Text', pmHighest, nil, Sys.Desktop);

C++Script, C#Script

Log["Warning"]("Warning Message Text", "Extended Text", pmHighest, null, Sys["Desktop"]);

Mobile

JavaScript, JScript

Log.Warning("Warning Message Text", "Extended Text", pmHighest, null, Mobile.Device("MyDevice").Desktop.Picture());

Python

Log.Warning("Warning Message Text", "Extended Text", pmHighest, null, Mobile.Device("MyDevice").Desktop.Picture())

VBScript

Log.Warning "Warning Message Text", "Extended Text", pmHighest, Nothing, Mobile.Device("MyDevice").Desktop.Picture

DelphiScript

Log.Warning('Warning Message Text', 'Extended Text', pmHighest, nil, Mobile.Device('MyDevice').Desktop.Picture());

C++Script, C#Script

Log["Warning"]("Warning Message Text", "Extended Text", pmHighest, null, Mobile["Device"]("MyDevice")["Desktop"].Picture());

Posting Images From Keyword Tests

You can post images to the test log by using any of the following operations:

  • The Post Screenshot operation - Posts the images as messages of the image type. This operation is a keyword test analogue to the Log.Picture method.

  • The Log Message operation - Posts messages accompanied by optional images (analogue to the Error, Warning, Message, Event, Checkpoint messages).

  • The Call Object Method or Run Code Snippet operations - You can use these operations to call the scripting methods mentioned in the previous section of this topic.

Using the Post Screenshot Operation

The easiest way to post a message to the test log is to use the Post Screenshot operation. This operation belongs to the Logging category. When you add an operation to the keyword test, TestComplete displays the Operation Parameters wizard, in which you can choose the window or control, whose image will be posted, specify the message text, extended text, priority and other parameters:

  • Open an existing keyword test for editing.

  • Drag the Post Screenshot operation to the test. After you released the mouse button, TestComplete will display the Operation Parameters wizard.

  • On the first page of the wizard, you can specify the window or control, whose image will be posted to the log. You can either type the window (or control) name into the Object box, or select the window or control from screen by using the target glyph or mouse pointer (to select a control in a mobile application, use Mobile Screen). You can also choose rectangular regions of a window or control.

    For more information on specifying the object, see the operation description. For information on specifying objects in mobile applications, see Selecting an Object on the Mobile Screen.

    Click Next to continue.

  • On the second page, specify the message text in the Message box and additional text in the Details box. Click Next to continue.

  • On the next page, you can see all of the operation parameters. The Picture parameter specifies the name of the window or control, whose image will be logged. The MessageText and AdditionalText parameters contain the message text and extended text that we specified on the second page of the wizard. You can modify other parameters as needed.

  • Click Finish to confirm the changes and to close the wizard.
Using the Log Message Operation

The Log Message operation has the Picture parameter that lets you specify the image to be posted to the log along with the message.

  • Open an existing keyword test for editing.

  • Drag the Log Message operation to the test. After you released the mouse button, TestComplete will display the Operation Parameters wizard.

  • On the first page of the wizard, specify the message type, text and extended text. Click Next to continue.

  • The second page will display all of the parameters of the operation. To specify the image, click the ellipsis button of the Picture parameter. This will invoke the Edit Parameter dialog.

  • In the dialog, do any of the following:

    • Choose Code Expression from the Mode drop-down list.

    • Specify the full name of the desired window or control in the Value edit box. For information on window and control names, see the Object Browser Naming Notation section.

    -- or --

    • Choose Onscreen Object from the Mode drop-down list.

    • Specify the desired window or control name in the Value box or click the ellipsis button of this box and choose the desired window in the ensuing Select Object dialog.

  • Click OK to apply the changes and to close the Edit Parameter dialog. This will return you to the Operation Parameters wizard.

  • Click Finish to close the wizard and to add the operation to the test.

Using the Call Object Method or Run Code Snippet Operation

You can post images to the test log by using the Call Object Method or Run Code Snippet operations in your keyword test. Both operations belong to the Test Actions category. You use them to call methods of the Log object described above of this topic.

Using the Call Object Method operation is simple:

  • Add the operation to your keyword test. TestComplete will display the Operation Parameters wizard.

  • On the first page of the wizard, type Log to specify the object, whose method will be called, and press Next.

  • On the next page, choose the method to be called. You can select any of the following methods:

    • Error
    • Warning
    • Message
    • Event
    • Checkpoint

    Press Next.

  • On the next page specify the desired window or control in the Picture parameter. Specify other parameters and click Finish to add the operation to the test.

To post an image with the Run Code Snippet operation, add this operation to the test and then type the script code that posts the image, into the Operation Parameters wizard. You can use the same code that is used in the script examples above.

See Also

Posting Messages, Images and Files to the Log
Picture Method
Message Method
Error Method
Warning Method
Event Method
Checkpoint Method
Post Screenshot Operation
Log Message Operation
Call Object Method Operation
Run Code Snippet Operation
Mobile Screen Window
Selecting an Object on the Mobile Screen (Android Testing)
Select an Object on the Mobile Screen (iOS Testing)

Highlight search results