Ask a Question

Get Unit name in script

SOLVED
Wamboo
Community Hero

Get Unit name in script

Does anyone know the solution to this problem?

 

https://community.smartbear.com/t5/TestComplete-General-Discussions/How-to-find-the-script-unit-name...

 

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.

3 REPLIES 3
AlexKaras
Community Hero

Hi,

 

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.

 

Regards,
  /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.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
TanyaYatskovska
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



Hi

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!

 

cancel
Showing results for 
Search instead for 
Did you mean: