cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with 'GeneralEvents_OnLogError'

SOLVED
Highlighted
Regular Contributor

Need help with 'GeneralEvents_OnLogError'

Hi All

 

I am trying to save the log when TestComplete encounters an error and stops. After much reading, searching I have this bit working.

 

function swceLogin(){
Browsers.Item("iexplore").Run("[APPLICATION URL]"); var browser = Sys.Browser("iexplore"); var page = browser.Page("*THC*"); var userName = page.FindChildEx("idStr", "txtUserName", 10, true, 10000); var userPass = page.FindChild("idStr", "txtPassword", 10); var btnLogin = page.FindChild("idStr", "lnkLogin", 10); userName.SetText("[USER]"); userPass.SetText("[PASSWORD]"); btnLogin.ClickButton(); var pName = page.FindChild("idStr", "Name", 15); //wrong valu for 'idStr' for the test to fail var btnSearch = page.FindChild("idStr", "ctl00_masterBodyContent_LinkButtonSearch", 15); pName.SetText("Morgan, Tom"); // test fails here btnSearch.ClickButton(); } function GeneralEvents_OnLogError(Sender, LogParams){ var sPath = "C:\\TestLog\\Log.mht"; if (aqFileSystem.Exists(sPath)) aqFileSystem.DeleteFile(sPath); Log.SaveResultsAs("C:\\TestLog\\Log.mht", lsMHT, false, lesCurrentTestItem); }

Problem is, the log does not contain the error message that caused the script to stop! Is there a way to save the log that includes the error message?

 

Thanks in advance for any help.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: Need help with 'GeneralEvents_OnLogError'

Hi,

 

Do you need to export the log at the moment when error occurs?

The reason of your problem is that the handler is called before the error is actually posted to the log. This gives you a chance to not post it to the log.

 

You may consider to set your Test Item to stop on error and move your code from the OnLogError handler to the OnStopTest one.

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members 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. Postings made by [Community Expert Group] members
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.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
5 REPLIES 5
Community Hero

Re: Need help with 'GeneralEvents_OnLogError'

Hi,

 

Do you need to export the log at the moment when error occurs?

The reason of your problem is that the handler is called before the error is actually posted to the log. This gives you a chance to not post it to the log.

 

You may consider to set your Test Item to stop on error and move your code from the OnLogError handler to the OnStopTest one.

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members 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. Postings made by [Community Expert Group] members
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.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Community Hero

Re: Need help with 'GeneralEvents_OnLogError'

The OnLogError event handler interrupts the log process.  IT is not until AFTER the event handler executes that the error gets written to the log.  So, by doing the export within the handler, you won't get the error in the log without explicitly putting it there.  You could try adding your export to the OnStopTest event handler instead.

I would suggest, also, before you do the export call Log.SaveToDisk to make sure you've flushed the latest entries to disk before you do the export.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Regular Contributor

Re: Need help with 'GeneralEvents_OnLogError'

Hi Alex

 

Thanks for your insight. Just tried it and it worked!! Smiley Very Happy I really appreciate your help.

 

Regards.

 

Dave

Regular Contributor

Re: Need help with 'GeneralEvents_OnLogError'

Hi Robert

 

Thanks for your and Alex's insight. I got it to work. To your point "... make sure you've flushed the latest entries to disk before you do the export.". I have done this:

  var sPath = "C:\\TestLog\\Log.mht";

  if (aqFileSystem.Exists(sPath)) 
  aqFileSystem.DeleteFile(sPath);

I thought it should delete the last 'Log.mht' file. If I am wrong, can you please tell me how I should do just that?

 

Regards.

 

Dave

 

Community Hero

Re: Need help with 'GeneralEvents_OnLogError'

Correct, that will delete the old file. @tristaanogre's suggestion was to call the save to disk so that the logs are already written when you export instead of residing only in memory. 


Thanks,
Carson

Click the Accept as Solution button if my answer has helped
New Here?
Join us and watch the welcome video:
API Testing Mistake #2
APITestingMistake#2
Top Kudoed Authors