cancel
Showing results for 
Search instead for 
Did you mean: 

Writing log messages of test to the file

SOLVED
Regular Visitor

Writing log messages of test to the file

Hi,

 

When TestComplete is being used, We try to write log messages which are come out of the "Log. Message()" or "Log.Error()" function to a text file in order to keep the log messages together as a log.txt. However, after creating a file, we try to use "Log.File()" function or  "SaveResultsAs()" to write logs messages to this file, It just created the file, could not write anything. Is there any way to keep log messages that are written in the test script in the txt file in a given directory?

 

as an example code;

function creatingAndWritingLogMessagesToTheTxtFile(){

//create a file

var filePath="C:\\.....";//Directory
aqFile.Create(filePath);

var logName="filePath"+".mth";

Log.SaveResultsAs(logName,lsMHT);

}

 

And in the functions how we can write the log messages to this created file that is created to keep log messages?

as an example code;

 

function testA(){

//....codes doing something

Log. Messages("Test Successful");

//Here How can we use that method (If it is useful) to write this log to that text file??

}

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Staff

Re: Writing log messages of test to the file

the log.error and log.message  operations will only output the corresponding messages to the log files that testcomplete generates. as I'm sure you've observed, within the test logs within the corresponding test step location, you should see those messages populate. 

if you wanted to store your test logs in a separate location, you could use log.saveresultas to output the testcomplete logs to a target directory in a supported format (html, mht, and xml), but this wouldn't be a text file.

https://support.smartbear.com/testcomplete/docs/reference/project-objects/test-log/log/saveresultsas...

-----------

if we wanted to generate a text file each time a test run fails or passes, you would most likely use the aqfile.writetotextfile operation (https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqfile/writetotextfile.htm...) based on either conditional statements or event handlers

 

Best,
Justin Kim

View solution in original post

3 REPLIES 3
Highlighted
Staff

Re: Writing log messages of test to the file

the log.error and log.message  operations will only output the corresponding messages to the log files that testcomplete generates. as I'm sure you've observed, within the test logs within the corresponding test step location, you should see those messages populate. 

if you wanted to store your test logs in a separate location, you could use log.saveresultas to output the testcomplete logs to a target directory in a supported format (html, mht, and xml), but this wouldn't be a text file.

https://support.smartbear.com/testcomplete/docs/reference/project-objects/test-log/log/saveresultsas...

-----------

if we wanted to generate a text file each time a test run fails or passes, you would most likely use the aqfile.writetotextfile operation (https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqfile/writetotextfile.htm...) based on either conditional statements or event handlers

 

Best,
Justin Kim

View solution in original post

Highlighted
Community Hero

Re: Writing log messages of test to the file

Hi,

 

If I got your question right and to expand a bit what was already said by @hkim5 :

if we wanted to generate a text file [...] based on [...] event handlers

Which means that you should implement event handlers for the OnLogMessage and OnLogError events and use these handlers to dump to text file whatever is going to be posted to test log.

 

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
================================
Highlighted
Community Manager

Re: Writing log messages of test to the file

Thank you for helping, Community!

 

@Merve Does this answer your question fully?


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors