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 recipe 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:
var picWindow = Sys.Desktop.ActiveWindow().Picture(); var picDesktop = Sys.Desktop.Picture();
picWindow
variable, will be placed into the log, unchanged:Log.Picture(picWindow, "Active window");
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");
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");
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.
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:
3.139.83.96