Forum Discussion

ory_z's avatar
ory_z
Contributor
14 years ago

LogParams changed behaviour on TC 8.5

Hi there,



I've noticed a change in the behaviour of the LogParams object in TC 8.5.

We use the OnLogError event to write the details of the error to an external text log. This is useful for when TC hangs or crashes (and the in built logs are lost) to help determine cause and at what stage of the test execution the failure happened.



My function looks something like this:



function GeneralEvents_OnLogError(Sender, LogParams)



  var errorMessage 

  //Log error text & additional text to external log

  errorMessage = LogParams.MessageText + "(" + LogParams.AdditionalText + ")"

  WriteToExternalLog( "!!! ERROR - " + errorMessage )

}



This worked fine for TC8, 8.1 and 8.2. However in TC8.5 the LogParams.AdditionalText return a very padded string, for example:



<html><style>body {font-family : Courier New, Arial; font-size : 10pt; font-weight : normal; padding : 14px 8px 8px 14px; margin : 0 0 0 0;} p {margin : 4px 0 4px 0; padding : 0 0 0 0;} h4 {font-size: 10pt; font-weight : bold; margin : 12px 0 0 16px; padding : 0 0 0 0;} table {margin-left : 16px; border-top: 1px solid grey;} td {font-size : 10pt; font-weight : normal; padding-left : 8px;} </style><body><p>An error occurred while calling the "ClickButton" method or property of the "<a href="lnamemapping://{09E818B6-F3E0-4BED-B332-DB57AC0208CC}.{49DF2E34-97FE-4320-8A5E-6B759ED384C2}">PlayBtn</a>" object.<br/>The object or one of its parent objects does not exist.</p><h4>Tested Object</h4><table cellpadding="0" cellspacing="0" noborder><tbody><tr><td><b>Alias:</b></td><td>Aliases.RIOS_SSC32.InviteUnit.PlayBtn</td><tr><td><b>Mapping item:</b></td><td>NameMapping.Sys.RIOS_SSC32.InviteUnit.PlayBtn</td></tr></tbody></table><h4>Missing Object</h4><table><tbody><tr><td><b>Alias:</b></td><td>Aliases.RIOS_SSC32</td><tr><td><b>Mapping item:</b></td><td>NameMapping.Sys.RIOS_SSC32</td></tr></tbody></table><p style="margin-top: 12px;"><a href="aqa-help://2201">Possible causes of the error</a></p></body></html>



I've attached a screenshot of an inspection of the LogParams object.



Thanks,

Ory
  • Hi Allen,



    Thanks for that. 



    Unfortunately it doesn't work.. Trying it with the error triggered from the Object Not Found error (using a call to an Alias that doesn't exist) results and a returned empty string. When debugging, the operation { = html.replace(stripAllTags, " "); } returns an empty string. This is easy to reproduce with the following code:




    function TestStripHTML()

    {

      Log.Message( stripHtml( "<html><style>body {font-family : Courier New, Arial; font-size : 10pt; font-weight : normal; padding : 14px 8px 8px 14px; margin : 0 0 0 0;} p {margin : 4px 0 4px 0; padding : 0 0 0 0;} h4 {font-size: 10pt; font-weight : bold; margin : 12px 0 0 16px; padding : 0 0 0 0;} table {margin-left : 16px; border-top: 1px solid grey;} td {font-size : 10pt; font-weight : normal; padding-left : 8px;} </style><body><p>An error occurred while calling the \"Visible\" method or property of the \"<a href=\"lnamemapping://{225B2166-C880-4BD1-BCCF-7A46171069A3}.{1BB7E949-7C88-4D15-9153-FED23F9B60D0}\">ConnectBtn</a>\" object.<br/>The object or one of its parent objects does not exist.</p><h4>Tested Object</h4><table cellpadding=\"0\" cellspacing=\"0\" noborder><tbody><tr><td><b>Alias:</b></td><td>Aliases.RIOS_SSC32.InviteUnit.ConnectBtn</td><tr><td><b>Mapping item:</b></td><td>NameMapping.Sys.RIOS_SSC32.InviteUnit.BitBtn4</td></tr></tbody></table><h4>Missing Object</h4><table><tbody><tr><td><b>Alias:</b></td><td>Aliases.RIOS_SSC32</td><tr><td><b>Mapping item:</b></td><td>NameMapping.Sys.RIOS_SSC32</td></tr></tbody></table><p style=\"margin-top: 12px;\"><a href=\"aqa-help://2201\">Possible causes of the error</a></p></body></html>" ) );

    }


    Any idea why?

  • Hi Ory,





    Here is the corrected version: 







    function stripHtml(html)

    {

      var stripStyles = new RegExp("(<style[^>]*?>(.+?)(</style[^>]*?>|$))", "g"); 

      var stripScripts = new RegExp("(<script[^>]*?>(.+?)(</script[^>]*?>|$))", "g");

      var stripAllTags = new RegExp("(<[^<]*?>)", "g");

      var text = html.replace(stripStyles, "");

      text = text.replace(stripScripts, "");  

      text = text.replace(stripAllTags, " ");

      

      // Expand common entities

      var entityMapping = {};       

      entityMapping["&quot;"] = "\"";

      entityMapping["&apos;"] = "'";

      entityMapping["&lt;"] = "<";

      entityMapping["&gt;"] = ">";

      entityMapping["&nbsp;"] = " ";

      entityMapping["&amp;"] = "&";  

      

      for (var key in entityMapping)

      {

        text = text.replace(new RegExp(key, "g"), entityMapping[key]);

      }

      

      // Remove duplicated spaces

      text = text.replace(new RegExp("(\\s){2,}", "g"), " ");

      

      return text;

    }







    The original RegExp was correct, it was just necessary to split it into multiple sub-expressions, which should be executed one by one.


  • Sorry for the (very) late reply. It was on my to-do list and I finally got to check your suggestion. 



    It works!



    Thanks, we will use it in our projects.



    Looking at the function it looks very simple, makes me wonder why 'regular expressions' always seem so complicated to write?

    Do you guys have a good guide to regular expressions you can recommend?
  • Awesome! never noticed there was a help topic about that. 



    It's pretty cool that you can even use them in find or replace.



    Thanks Allen.
  • For future reference of anyone finding this thread, I've added new lines instead of breaks and 2 new lines instead of paragraph end tags. I've also trimmed leading spaced.



    The function now looks like this:


    function Strip_HTML( html ) 



      var stripStyles = new RegExp( "(<style[^>]*?>(.+?)(</style[^>]*?>|$))", "g" );  

      var stripScripts = new RegExp( "(<script[^>]*?>(.+?)(</script[^>]*?>|$))", "g" ); 

      var stripAllTags = new RegExp( "(<[^<]*?>)", "g" ); 

      var text = html.replace( stripStyles, "" );

       

      text = aqString.Replace( text, "<br/>", "\r\n" );

      text = aqString.Replace( text, "</p>", "\r\n\r\n" );

      text = text.replace( stripScripts, "" );   

      text = text.replace( stripAllTags, " " );

      text = aqString.Trim( text, 1 ); 

       

      // Expand common entities 

      var entityMapping = {};        

      entityMapping["&quot;"] = "\""; 

      entityMapping["&apos;"] = "'"; 

      entityMapping["&lt;"] = "<"; 

      entityMapping["&gt;"] = ">"; 

      entityMapping["&nbsp;"] = " "; 

      entityMapping["&amp;"] = "&";   

       

      for (var key in entityMapping) 

      { 

        text = text.replace(new RegExp(key, "g"), entityMapping[key]); 

      } 

       

      // Remove duplicated spaces 

      text = text.replace(new RegExp("(\\s){2,}", "g"), " "); 

       

      return text; 

    }