Ask a Question

Get Unit name in script

Community Hero

Get Unit name in script

Does anyone know the solution to this problem?


How do I get the name of the file you were running the script from?
Having this name as the data to be used in the current script.

Community Hero



Actually, solution for JScript (and, hopefully, JavaScript) is provided in the thread that you referenced.

For VBScript and DelphiScript this is not possible.

Don't know for Python.


  /Alex [Community Hero]
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
SmartBear Alumni (Retired)

Hi @Wamboo,

For JavaScript you can use this code:

function Afunction()
  var theName = arguments.callee.toString().match(/function (\w*)/)[1];


Tanya Yatskovskaya
SmartBear Community and Education Manager


Thank you for your answers. 


@TanyaYatskovska  this code refers to the name of the running function and not to the name of the file in which the function is stored.


I found a solution how to find the name of the file from which the function is run.



function retrievedNameRelatedUnit() {
     let testItemNameFull = Project.TestItems.Current.ElementToBeRun.Caption;
     var formatTestItemNameFull = testItemNameFull.split(/\Name-Full.split(/\Name-- /));
     return formatTestItemNameFull[1];


there is an array with the file name in the variable.


You can use the file name (Unitu) to dynamically run the file by e.g. aqObject Object


TY for all your help!


Showing results for 
Search instead for 
Did you mean: