





















































(For more resources related to this topic, see here.)
TestComplete allows committing various types of messages to the log: ordinary messages, warnings, logs, and so on.
In this section, we will consider examples of how to use these messages.
Create a file with the name myfile.txt in the root directory of C:.
In order to see examples of all the message types in the log, the following steps should be performed:
Create and launch the following function:
function testMessages() { Log.Event("An event", "Event additional Info"); Log.Message("A message", "Message additional Info"); Log.Warning("A warning", "Warning additional Info"); Log.Error("An error", "Error additional Info"); Log.File("C:\somefile.txt", "A file posted to the log"); Log.Link("C:\somefile.txt", "A link to a file"); Log.Link("http://smartbear.com/", "HTTP link"); Log.Link("ftp://smartbear.com/", "FTP link"); }
In the result, we will get the following screenshot of the log
In the given example, we have used four different types of messages. They are as follows:
These four types of message are based on several parameters. The first of them is a string that we observe in the log itself; the second one contains additional information which can be seen in the Additional Info tab, if the message has been clicked on. The second parameter is optional and can be omitted as well as all other parameters.
There are two more types of messages:
These two types of message accept the link as the first parameter, and then the message parameters, and those pertaining to the additional information (as the previous four). Only the first parameter is mandatory.
Sometimes, it is necessary to place an image into the log; often, it may be a window screenshot, an image of a controls element, or even that of the whole of the screen. To this end, we use the Log.Picture method.
In this section we will consider different ways to place an image into the log.
The following steps should be performed to place an image to the log:
First of all, we will create two image objects for the enabled window and the whole of the screen:
var picWindow = Sys.Desktop.ActiveWindow().Picture(); var picDesktop = Sys.Desktop.Picture();
The image of the active window, now being stored in the picWindow variable , will be placed into the log, unchanged:
Log.Picture(picWindow, "Active window");
The image of the desktop is reduced by four times via the Stretch method , and then saved on to the file with the help of the SaveToFile method:
picDesktop.Stretch(picDesktop.Size.Width/2, picDesktop.Size.Height/2); picDesktop.SaveToFile("c:\desktop.png");
Now we go about creating a new variable of the Picture type, loading up an image into it from the earlier saved file, and then placing the same into the log:
var pic = Utils.Picture; pic.LoadFromFile("c:\desktop.png"); Log.Picture(pic, "Resized Desktop");
As a result of function's execution, the log will contain the two images placed therein: that of the enabled window at the moment of test execution, and that of the reduced desktop copy.
The Log.Picture method has one mandatory parameter that is, the image itself; the other parameters being optional.
Images of any of the onscreen objects (of a window, of a singular controls element, of the desktop) can be obtained via the Picture method. In our example, with the help of the method, we get the image of the desktop and that of the active window. Instead of the active window, we could use any variable that corresponds to a window or a controls element.
Any image can be saved onto the disk with the help of the SaveToFile method. The format of the saved image is determined by its extension (in our case, it is the PNG).
If it's necessary to obtain a variable containing the image from the file, we are supposed to create an empty variable placeholder with the help of the Utils.Picture property , and then with the help of the LoadFromFile method , we upload the image into it. In the future, one could handle the image as any other, received with the help of the Picture method.
Great-size images can be minified with the help of the Stretch method. The Stretch method uses two parameters: the new width and height of the image. With the help of the Size.Width and Size.Height properties , we could zoom in or out on the image in relation to its original size, without setting the dimensions explicitly.
With the help of the Picture method , we could obtain not only the image of the whole window or a controls element, but just a part of it. For example, the following code gets an image of the upper left square of the desktop within the sizing of 50 x 50 pixels:
var picDesktop = Sys.Desktop.Picture(0,0, 50, 50);
The values of the parameters are as follows: coordinates of the left and right top corner, and its width and height.
There is one important project setting which allows automatic posting images in case of error. To enable this option, right-click on the project name, navigate to Edit | Properties, click on Playback item from the list of options, and enable checkbox Post image on error.
Apart from changing the dimensions of the image, TestComplete allows for the execution of several, quite complicated imaging manipulations. For example, the comparison of the two images (the Compare method ), searching for one image inside the other (the Find method ), and so on. Click on the following link to get to know more about these possibilities: