cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Highlighted
Occasional Contributor

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
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Expert

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


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

View solution in original post

4 REPLIES 4
Highlighted
Regular Contributor

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

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...
Highlighted
Community Expert

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


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

View solution in original post

Highlighted
Occasional Contributor

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

@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 .

Highlighted
Occasional Contributor

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

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
New Here?
Join us and watch the welcome video:
Announcements
Script Wanted
Let's start July with new challenges!

Create a script to pass custom command-line arguments as a test parameter for the TechCorner tag!

Will you dare to take the challenge?


Top Kudoed Authors