Forum Discussion
AlexeyKolosov
14 years agoStaff
Hello,
Thank you for the detailed description of your problem. As far as I understand, you need to cancel posting entries (messages, warnings, errors, etc.) to the log if your test script runs with errors. That is, you need to remove particular entries from the log of the current test run, rather than remove the whole execution log (shown in the Project Explorer panel), right?
If so, I can suggest the following solution:
Handle TestComplete log events (OnLogMessage, OnLogWarning, etc.). In the event handler, you can block posting the current item to the Test Log, but write the item information to a temporary variable. If the test runs without errors, you'll be able to post the log information stored in the temporary variable to the TestComplete log from your script. If the test runs with errors, and you don't want its execution results to be present in the log, you just don't post the temporary variable contents to the log.
When implementing this suggestion, you will need to handle all OnLog<...> events so that you can completely redefine the TestComplete log's logic.
To help you understand my suggestion, I will demonstrate it with some code below. However, please note that the suggested approach has some restrictions:
1. You cannot post pictures to the log.
2. Log entries timestamps cannot be modified (the Time column in the Test Log panel), so you have to add a correct timestamp to an entry's Message contents from script.
3. Navigation to script lines from the Test Log won't work.
So, the sample script demonstrating my idea is below. Hopefully, it will be useful for you:
// This script illustrates how to handle TestComplete Log events.
// It uses Notepad as the tested application.
// In order to make the script work, link the
// GeneralEvents_OnLogError and GeneralEvents_OnLogCheckpoint routines to the corresponding events.
// Before running, add a new variable called UseMyLog to project temporary variables.
var errCount = 0;
var MY_LOG = new Array();
function MyTest()
{
var edit = Sys.Process("notepad").Window("Notepad", "*").Window("Edit");
aqObject.CheckProperty(edit, "wText", cmpEqual, "test", false);
}
function Main(){
if(TestedApps.Count == 0)
TestedApps.Add("Notepad", "C:\\Windows\\System32\\Notepad.exe");
TestedApps.Items("Notepad").Run();
var edit = Sys.Process("notepad").Window("Notepad", "*").Window("Edit");
// Start tapping
Project.Variables.UseMyLog = true;
// Set incorrect text to emulate an error
edit.SetText("fail");
// Start the test
MyTest() ;
if(errCount >0){
errCount = 0;
MY_LOG = new Array();
// Set a correct text and start the test again
edit.SetText("test");
MyTest();
}
// End tapping
Project.Variables.UseMyLog = false;
if(errCount == 0)
PostLog();
}
function PostLog()
{
for(i = 0; i< MY_LOG.length; i++){
var attr = Log.CreateNewAttributes();
attr.ExtendedMessageAsPlainText = false;
var date = MY_LOG["Date"];
date = aqConvert.DateTimeToFormatStr(date, "%m/%d/%Y %H:%M");
eval("Log." + MY_LOG["Type"] +
"(date + \" | \" + MY_LOG[\"Str\"]," +
"MY_LOG[\"StrEx\"]," +
"MY_LOG[\"Priority\"]," +
"attr)");
}
}
function AddLogItem(Type, LogParams)
{
var rec = new Array();
MY_LOG[MY_LOG.length] = rec;
rec["Date"] = aqDateTime.Now();
rec["Priority"] = LogParams.Priority;
rec["Str"] = LogParams.Str;
rec["StrEx"] = LogParams.StrEx;
rec["Type"] = Type;
}
function GeneralEvents_OnLogError(Sender, LogParams)
{
if(!Project.Variables.UseMyLog)
return;
errCount +=1;
LogParams.Locked = true;
AddLogItem("Error", LogParams);
}
function GeneralEvents_OnLogCheckpoint(Sender, LogParams)
{
if(!Project.Variables.UseMyLog)
return;
LogParams.Locked = true;
AddLogItem("Checkpoint", LogParams);
}
Related Content
Recent Discussions
- 45 minutes agoSlickRick
- 2 hours agoSlickRick
Name Mapping Issue
Solved4 hours agokgreger1