Forum Discussion

binithb's avatar
binithb
Occasional Contributor
11 years ago
Solved

How to know the test function name, test file name and project name from a test complete function

Hi ,



We are trying to execute a test function and we need to know the name of the test function and the name of the current file from within the test function.

something like 




function TestGlobalSearchClientContacts(){

 var this_function_name = ??

 var this_file_name = ??

 .

 .

 .

 testcode 


 


}



How can we achieve this in Test Complete

We are using JScript and TC version is 9



Thanks,

Binith

  • Hi binith, as you are using JScript, you can extract the function name from the function arguments as described here. (you will need to scroll down a few posts to find the JScript examples)



    As far as I am aware, however, there is no way to obtain the file or project name.


     


    In the past, one the rare occasion I have wanted this information, I simply place the values in a global var in the Script Unit.


     


    Regards,


    Phil Baird

4 Replies

  • hlalumiere's avatar
    hlalumiere
    Regular Contributor
    You can't, the fact you think you can is worrisome. A variable declared inside a procedure has scope only within that procedure. Besides, you already know what the values are, since you wrote them in the procedure to begin with.



    Or maybe I misread and what you need is the name of the current script file? Obvioulsy you know the procedure name, since you are writing the procedure right now...
  • Philip_Baird's avatar
    Philip_Baird
    Community Expert

    Hi binith, as you are using JScript, you can extract the function name from the function arguments as described here. (you will need to scroll down a few posts to find the JScript examples)



    As far as I am aware, however, there is no way to obtain the file or project name.


     


    In the past, one the rare occasion I have wanted this information, I simply place the values in a global var in the Script Unit.


     


    Regards,


    Phil Baird

  • binithb's avatar
    binithb
    Occasional Contributor
    @Hugo Lalumiere , 

    You can't, the fact you think you can is worrisome. A variable declared inside a procedure has scope only within that procedure. Besides, you already know what the values are, since you wrote them in the procedure to begin with.



    :) I didnt quite get whats worrisome, most modern programming languages support extracting the function name from within a function , and after posting this question I have found out that I can do it from jscript using "arguments.callee.toString()



    And my question is not about how to know the name of the function and file when I am writing it :) , for one file or one function,  its about knowing it at run time .

  • binithb's avatar
    binithb
    Occasional Contributor
    Hi Phil Baird,

    Yeah I am using arguments.callee.toString() to get the function name , its working.

    Like you said there is no way I can figureout the file name so doing some work around for that.



    Thanks