Scripting access to log messages
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Scripting access to log messages
Hi,
I have created a script that writes out tests results to a SQL database. I have got a bit stuck on the last part however. I was hoping to use the general event of on log error to write out the messages to the table.
I can easily write messages to the log but how do I pull out the error messages that TestComplete writes to the log. Any help would be greatly appreciated.
Regards,
MegO
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In the OnLogError event handler, you have available the LogParams object for the "current" error message. That object has a MessageText and an AdditionalText property which contains the text that is written out in the TestComplete log. See https://support.smartbear.com/testcomplete/docs/reference/project-objects/test-log/log-params/proper...
Robert Martin
[Hall of Fame]
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
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So I could do something like this:
function GeneralEvents_OnLogError(Sender, LogParams)
{
TestComment = LogParams.AdditonalText
}
and it would return the error logged?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
AdditionalText will return what you see in the "Additional Info" tab in the TestComplete log. MessageText will return the main text of the error message.
Robert Martin
[Hall of Fame]
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
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi TristanOgre,
Thank you for the help you have given. I am however still struggling to read the information from LogParams.AdditionalText and write it out elsewhere. Do you have an example you could share?
I think my other option would be to go down this path: https://support.smartbear.com/testcomplete/docs/reference/project-objects/test-log/logresults/textlo... and pull the text out to a seperate file to use?
Many thanks,
MegO
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Basically, what you have listed before is a good start to the code.
function GeneralEvents_OnLogError(Sender, LogParams) { TestComment = LogParams.AdditonalText }
This assigns the value of "AdditionalText" to a variable called "TestComment". so, your next step would be to take "TestComment" and pass it in to some sort of function or value that you would then write out to a file or to SQL.
I guess the question I have for you is this:
What is your ultimate aim? Do you want to only write out the information for errors? do you want the whole log file output? You mentioned writing to SQL. Is that your preferred destination? For what purpose are you doing this output? We'd be happy to help but we need to know a bit more of what your desire is here.
Robert Martin
[Hall of Fame]
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
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi TristaanOgre,
This is what I would essentially be be doing:
function GeneralEvents_OnLogError(Sender, LogParams)
{
testStatusComments = LogParams.AdditonalText
var dbObj;
dbObj = ADO.CreateADOQuery();
dbObj.ConnectionString = "MyConnectionString";
dbObj.SQL = "Update Test_Status set testStatusComments = testStatusComments + '" + testStatusComments + "' Where TestSectionName = '" + testname + "' AND TestStartTime Like '%" + TestDate + "%'";
dbObj.ExecSQL();
}
This will add to other information currently being written out to SQL on the start and stop events.
The eventual aim is to start using reporting services so that we can can see very quickly if there are any patterns in failure.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Generally speaking, that looks fine... I haven't run it or anything but it looks about right. What seems to be the problem with it that you can't access the information?
Robert Martin
[Hall of Fame]
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
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yep, Its just not returning anything 😞
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If there is no Additional Info on the log, AdditionalText will be empty. Hence why there are two different text values on LogParams. If you want the information in the main log, you want MessageText. If you want the information that shows in the Additional Info tab, you want AdditionalText. So, if your log message doesn't have any Additional Info (which is possible), AdditionalText will be empty.
Robert Martin
[Hall of Fame]
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
Vegas Thrill Rider
Extensions available
