Forum Discussion

CBleunven's avatar
CBleunven
Contributor
12 years ago

More explicit Log message

Hi,

I actually develop a "Framework" to test our application with TestComplete. Some actions are actually trace with the following message in the log :

The window was clicked with the left mouse button.


that is not really explicit.

I would like to know if there is a way to substitute this message with something more explicit ?



There is the possibility to "embed" the log in a specific folder more explicit

Log["AppendFolder"]("Click on the element X");

perform the click

Log["PopLogFolder"]();


but it starts to be a bit hard to read the entire log.



The other possibility I see is the EventHandler, but in this case I don't not see how I can obtain for each log message that is intercepted,  the information I want to add (the name of the calling function).



Thank you for your help,

Christophe






5 Replies

  • Julia_K's avatar
    Julia_K
    SmartBear Alumni (Retired)
    Hello Christophe,

    Currently, TestComplete does not provide any straightforward way to customize such log messages. To make log messages more explicit, you can use the workarounds you mentioned in your previous message (to use the Log.AppendFolder method or log event handlers). 

    We have an appropriate suggestion in our database to make such a log message more informative, and your message has increased its rating. Could you please give a bit more detail on the information you want the log messages to include, or give an example of the log messages you need? We could use this information when implementing this functionality.

    Thank you.
  • Hello Julia,

    thank you for your reply.

    I've seen also that I may try to use the LockEvents Method of the Log object to block one message and substitute it with my customized message. If I've well understood, the Log will not be added if everything is OK but will appear if the action fail, providing the required information. I need to test such solution, that will produce lighter Log results than the previous one.



    About the improvement of the current behavior, my "wish" will to be able to custom the message for actions that insert a message in the log (like Click).

    A possibility could be to have an overrided function with a parameter that contains information on the customized message like the text to be displayed, the additional information, the priority, should we take a picture ... in fact all information sent to the Message method of Log, but embedded in a single object that could be previously set.



    in "pseudo code" the result for me could look like this:



    MyPanel.Click(); // add the default message "The window was clicked with the left mouse button. " in the log

    var logMessage = new logMessage("Click on my very special drawing panel");

    logMessage.setPriority(low);

    logMessage.takeAPicture(whenFail); //May be also never or always

    // whatever additional parameter we want

    MyPanel.Click(logMessage); // add the "Click on my very special drawing panel" message in the log with low priority.





    Thank you for your interest in my remarks,

    Best,

    Christophe
  • Julia_K's avatar
    Julia_K
    SmartBear Alumni (Retired)

    Hello Christophe,

    Thank you for your feedback and for the provided details.

    Please note that the event log message customization you need can be partially achieved by creating a custom handler for the onLogEvent event. The LogParams parameter of the onLogEvent hander contains the text of the message to be posted to the text log. You can retrieve that text and replace it with a custom message.

    For example:



    function GeneralEvents_OnLogEvent(Sender, LogParams)

    {

    ...

    if (aqString.StrMatches("The window was clicked with the left mouse button", LogParams.MessageText))

    {

      if (aqString.Find(LogParams.AdditionalText, "Window(\"Notepad\"") > -1)

      {

        LogParams.MessageText = "The Notepad window was clicked with the left mouse button.";

      }

    }

    ...

    }


    Or you can use the Log.LockEvents and Log.UnlockEvents methods to prevent any event messages from being posted to the log and use the Log.Event method to post your own custom event messages.

    For example:



    function Test()

    {

      ...

      var btnOk = dlgAboutNotepad.Window("Button", "OK");

      

      Log.LockEvents(); // Prevents event messages from being posted to the test log

      btnOk.ClickButton(); // The standard "The button was clicked" even message will not be posted

      

      Log.UnlockEvents(); // Re-enables posting event messages to the test log

      var str = "The OK button of the About Notepad window was clicked with the left mouse button"; 

      Log.Event(str); // Posts a custom event message to the test log

      ...

    }


    Please let us know if you need anymore assistance.

    Thank you.

  • Hello Julia,

    thank you for your attention.

    I guess that the limit of the first solution is that I need, in the GeneralEvents_OnLogEvent, to discriminate from the origin of the message. If I've two or more possible sources of click in my set of functions, how may I discriminate between them ?

    Should I split a project in micro projects, each with one click and one event handler ? Moreover, I guess that only the event handler of the running project is used ?

    In the other and if I have a way to discriminate, I will have a "switch" instruction with at least 100 "case", I'm not sure about the maintenance possibility of such code :-)

    I should study the possibility to pass through a project variable to do the exchange between the function that perform the click and the function that handle the event.

    Thanks for your help,

    Christophe
  • Julia_K's avatar
    Julia_K
    SmartBear Alumni (Retired)
    Hello Christophe,

    Should I split a project in micro projects, each with one click and one event handler ? Moreover, I guess that only the event handler of the running project is used ?


    Yes, you are right, only the event handler of the running project is used during the test run.

    I guess, splitting your project into multiple projects, each of them simulating an individual click, will make your test really difficult to maintain.

    You can try using project variables to pass the required data to the OnLogEvent handler.

    Good luck with your testing.