Thursday, April 8, 2010

QTP - How to handle different messages generated in the test or framework

QTP - How to handle different messages generated in the test or framework


During test execution based on the requirements different messages are generated. All the messages need to be captured and printed in the log file at the end of test execution.


Attaching sample log file screen shot.


To capture the messages I have created the function funMessages(sMessages), this function can store any number of messages. Once the test is completed we can dump the data into log files.


This function will capture the messages with time stamp, created two global variables gsMessagesCounter, gsMessages (array).

Function funMessages(sMessages)
        gsMessagesCounter = gsMessagesCounter + 1
        gsMessages(gsMessagesCounter) = Now() & "  -  " & sMessages
End Function


Sample code to write the above captured data into a log file

Set oFS=createobject ("scripting.filesystemobject")
Set oNotepad = oFS.createtextfile(gsTestSummaryFilePath)

oNotepad.writeline("System Generated Messages Log")          
oNotepad.writeline("-----------------------------------------------")    
For iCounter = 1 to gsMessagesCounter
        oNotepad.writeline gsMessages(iCounter)    
Next

oNotepad.Close

Set oFS = Nothing
Set oNotepad = Nothing   

Above mentioned code can capture any number of messages with time stamp and safely dump on the log file.




----

No comments:

Post a Comment