Forum Discussion

mateenhussain's avatar
mateenhussain
Occasional Contributor
15 years ago

Create Log even though TestComplete fails executing

Hi



I have created a custom log for my tests, coz

1) The default logs created by TC all have a prefix "Testrestults" and it becomes hard to identify by looking at their names. And sometimes they are overwritten.

2) I want all of them to go into a fixed folder for archiving.



The way I do it is:



[TestCase]

function test1()

{

.....

CreateLog("test1");

}



function CreateLog(testCaseName)

{

....

Log.SaveResultsAs(path+testCaseName+".mht",2);

}



The problem with this, whenever TestComplete ends execution abruptly due to an error, it never reaches the line "CreateLog("test1");" (which is expected). And as a result I dont get any logs.



I even tried using try{}finally{} block around my testcase, but still it doesn't execute finally, rather simply quits without any log. What can I be doing wrong? Any suggestions?



Thanks,

Mateen

3 Replies

  • Mateen,



    Use the event on OnStopTest to call your CreateLog("test1");




    Thankyou

  • mateenhussain's avatar
    mateenhussain
    Occasional Contributor
    Hi Ahmed



    Thanks for the tip. Is there anyway I can find out from the event generated, I can find out more details about the event, like which test, which file, lineno threw the exception which caused TC to stop testexecution.



    Thanks,

    Mateen
  • Hi Mateen,




    This function checks the execution result for each test item (whether there were errors or not).




        function GeneralEvents_OnStopTest(Sender)

        {

            if (Log.ErrCount == 0)

                CreateLog(Project.TestItems.Current.Name, false);

            else

                CreateLog(Project.TestItems.Current.Name, true);

        }




    You need to modify the CreateLog function definition in the following way:




        function CreateLog(testName, isTestFailed)

        {

            if (true == isTestFailed) {

                ...

            }

            ...

        }