Forum Discussion

cokyn's avatar
cokyn
Contributor
12 years ago

JScript runtime error when "OnStopTest" event handled

Hello everyone,



could you please help me with the following problem? I have created "OnStopTest" handler to export logs if the latest test item has been reached. I used the following code for handler




function



STOP_OnStopTest(Sender)



{



var LastTestItem=Project.Variables.LastTestItem;



var CurrentTestItem=Project.TestItems.Current.Name;



var logpath=Project.Variables.Log_Path;

 



if (CurrentTestItem==LastTestItem)



{ Log.SaveResultsAs(logpath, lsHTML);



Log.Message("The last test item " + LastTestItem + " has been executed.");}



else

{Log.Message("The test item " + CurrentTestItem + " has been executed.");}





When I run the project and current test item = the last item then logs are correctly exported but the test item itself fails with message "Microsoft JScript runtime error." It looks like, there is some problem with this line var CurrentTestItem=Project.TestItems.Current.Name; 



Any ideas will be appreciated.



Martin



 



 


  • Hi Martin.



    Could you tell us the actual value of Project variables LastTestItem and Log_Path ?

    Beside, can you post the additionnal information of the JScript runtime error ?

    Keep in mind that Project.TestItems.Current might be undefined if you are running your test item from TestComplete IDE. I guess, you have to run a complete Project or ProjectSuite to be able to get something out of this variable.



    You should try to enable debugger and run your test to find out.


  • One more important information - the test item is networksuite task
  • Following up on what MGDIS TIA said, if the test is being run on its own, then the variable will be undefined. If you run the test as part of Project or Project Suite instead of by itself, you should get the Test Name (the name that it was given when added to the Project).



    I used a 'try, catch' to give the variable a name of "Unknown Test Name" so I could run these test by themselves without an error coming up.