cancel
Showing results for 
Search instead for 
Did you mean: 

Disable warning about text being truncated

SOLVED
tphillips
Community Leader

Disable warning about text being truncated

I am writing a test that checks that when it enters text in a text field that has a maxLength set, the text gets truncated. I noticed that TestComplete (helpfully) logs a Warning when it tries to enter text (using SetText()) which is too long into a field with maxLength set.

 

Short of disabling the Log before setting the text and re-enabling afterwards, is there any way to tell TestComplete I don't care about if the text gets truncated (I am validating that myself, I expect it to get truncated).

 

I could use an event to catch when it's about to log a warning and check the warning text, but I would like to avoid that if possible.


--------------------
QA Systems Architect
1 ACCEPTED SOLUTION

Accepted Solutions
BenoitB
Community Hero

Re: Disable warning about text being truncated

Use the onLogWarning event.

 

2 ways, check the Sender object to filter on source basis or check the LogParams to filter on message basis.

 

Below a sample of message basis filtering :

 

var globals = {};

globals.WARNINGTOSKIP = ['The text cannot be fully entered', 'The length is too long', 'Another message to skip']; // Array of the warnings message to skip
globals.IGNOREWARNING = false; // True then convert Log.Warning into Log.Message
  function GeneralEvents_OnLogWarning(Sender, LogParams) {
    // Detect if, based on log message, it's a warning to be totally ignored
    let skip = false;
    for (let i = 0; i < globals.WARNINGTOSKIP.length; i++) {
      skip = skip == false ? aqObject.CompareProperty(LogParams.MessageText, cmpContains, globals.WARNINGTOSKIP[i], false, lmNone) : true;
    }
    if (skip) {
      Log.Message(LogParams.MessageText);
      LogParams.Locked = true;
    }
    else {
      // If just message instead of warning
      if (globals.IGNOREWARNING) {
        Log.Message(LogParams.MessageText, LogParams.AdditionalText);
        LogParams.Locked = true;
      }
      else {
        // Need to switch to avoid reentrancy
        let f                      = GeneralEvents_OnLogWarning;
        GeneralEvents_OnLogWarning = null;
        Log.Warning(LogParams.MessageText, LogParams.AdditionalText);
        GeneralEvents_OnLogWarning = f;
        LogParams.Locked           = true;
      }
    }
  }

 

 

Un sourire et ça repart

View solution in original post

5 REPLIES 5
BenoitB
Community Hero

Re: Disable warning about text being truncated

Use the onLogWarning event.

 

2 ways, check the Sender object to filter on source basis or check the LogParams to filter on message basis.

 

Below a sample of message basis filtering :

 

var globals = {};

globals.WARNINGTOSKIP = ['The text cannot be fully entered', 'The length is too long', 'Another message to skip']; // Array of the warnings message to skip
globals.IGNOREWARNING = false; // True then convert Log.Warning into Log.Message
  function GeneralEvents_OnLogWarning(Sender, LogParams) {
    // Detect if, based on log message, it's a warning to be totally ignored
    let skip = false;
    for (let i = 0; i < globals.WARNINGTOSKIP.length; i++) {
      skip = skip == false ? aqObject.CompareProperty(LogParams.MessageText, cmpContains, globals.WARNINGTOSKIP[i], false, lmNone) : true;
    }
    if (skip) {
      Log.Message(LogParams.MessageText);
      LogParams.Locked = true;
    }
    else {
      // If just message instead of warning
      if (globals.IGNOREWARNING) {
        Log.Message(LogParams.MessageText, LogParams.AdditionalText);
        LogParams.Locked = true;
      }
      else {
        // Need to switch to avoid reentrancy
        let f                      = GeneralEvents_OnLogWarning;
        GeneralEvents_OnLogWarning = null;
        Log.Warning(LogParams.MessageText, LogParams.AdditionalText);
        GeneralEvents_OnLogWarning = f;
        LogParams.Locked           = true;
      }
    }
  }

 

 

Un sourire et ça repart

View solution in original post

tphillips
Community Leader

Re: Disable warning about text being truncated

Yeah, I was hoping to do it without having to go all-out and use an event like this.

I have ended up just disabling logging when I know I am setting text that's too long and re-enabling it afterwards.


--------------------
QA Systems Architect
BenoitB
Community Hero

Re: Disable warning about text being truncated

I understand that you want to keep things in KISS principle and i was like you until a day i lost several hours because an error occured inside Log.Enabled off section ..  :^)

So ideally you should use a try .. finally pattern for the log off/on.

 

Advantages of event method are :

- Event exists for that kind of action

- It keep things centralized (reduce cost of maintenability)

- It allows you to add other stuff like making choice if real log made will be warning or message or even error or like avoiding multiple entries of same log or adding additionnal informations or ...

 

Yes this is heavier but once ..

 

Un sourire et ça repart

AlexKaras
Community Hero

Re: Disable warning about text being truncated

@BenoitB :

        // Need to switch to avoid reentrancy
        let f                      = GeneralEvents_OnLogWarning;
        GeneralEvents_OnLogWarning = null;
        Log.Warning(LogParams.MessageText, LogParams.AdditionalText);
        GeneralEvents_OnLogWarning = f;
        LogParams.Locked           = true;

Great piece of code!

Not sure if it works using any other but JavaScript language in TC... Need to check.

 

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
tphillips
Community Leader

Re: Disable warning about text being truncated

Yeah I was worried about leaving logs disabled if something went wrong too. I will give the events a go.

 

@AlexKaras I imagine it will likely work like that in python too.


--------------------
QA Systems Architect
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors