cancel
Showing results for 
Search instead for 
Did you mean: 

Get Unit name in script

SOLVED
Highlighted
Community Leader

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Leader

Re: Get Unit name in script

Hi

Thank you for your answers. 

 

@TanyaGorbunova  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!

 

View solution in original post

3 REPLIES 3
Highlighted
Community Hero

Re: Get Unit name in script

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
================================
Highlighted
Community Manager

Re: Get Unit name in script

Hi @Wamboo,

For JavaScript you can use this code:

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

 

---------
Tanya Gorbunova
SmartBear Community Manager

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
Highlighted
Community Leader

Re: Get Unit name in script

Hi

Thank you for your answers. 

 

@TanyaGorbunova  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!

 

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!

Challenge Status

How to execute remote test and obtain results via Test Runner REST API

Participate!

Comparing content of HTML table with Excel file data

Participate!

Compare HTML table with Excel file and correct data in the file

Participate!

Retrieve Data from a Web Page

Participate!
Top Kudoed Authors