Posting messages to the log

TestComplete allows committing various types of messages to the log: ordinary messages, warnings, logs, and so on.

In this recipe, we will consider examples of how to use these messages.

Getting ready

Create a file with the name myfile.txt in the root directory of C:.

How to do it...

In order to see examples of all the message types in the log, the following steps should be performed:

  1. 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:

    How to do it...

How it works...

In the given example, we have used four different types of messages. They are as follows:

  • Log.Event: This message is an event which occurs when TestComplete interacts with a tested application. Usually, messages of this type are placed into the log at the point of text input or mouse-clicks; however, we can also place custom-made events into the log.
  • Log.Message: This message is an ordinary message that is usually used for prompting a user concerning current actions that are being executed by the script (usually, of a higher level than that of the events; for example, creation of a user, searching for a record, and so on).
  • Log.Warning: This message is a non-critical error. It is used in case the results of the check are different from those expected; nonetheless, execution of the script can carry on.
  • Log.Error: This message is a critical error usually used when an error is a critical one, making any further execution of the test would be futile

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:

  • Log.File: This message copies the assigned file into the file with the log, and places a reference-pointer to it. Meanwhile, TestComplete renames the file to avoid naming conflicts, leaving only the original extension intact.
  • Log.Link: This message places a link to the web page or a file, without making a copy of the file itself in the folder with the log. On clicking on the link, the file will open with the help of the associated program or a link in the browser.

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.

See also

  • The Posting screenshots to the log and Creating folders in the log recipes
  • Also, if you want to learn more about additional parameters of different log messages, you can refer to the corresponding help pages by navigating to http://support.smartbear.com/viewarticle/32871/
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.171.107