Ask a Question

Is there a way to return the name of the current sub routine or function?

adrian_g
Occasional Contributor

Is there a way to return the name of the current sub routine or function?

Hi All,



Is there a way to return the name of the current sub routine or function that is being run. It would be nice to enter into the log.



I am currently coding in VB Script.



I assume there is no way to do it using VB script but is there a TestComplete inbuilt function?



Thanks  heaps,

Adrian
29 REPLIES 29
Marsha_R
Champion Level 3

I'd like it in keyword tests too please.
TanyaYatskovska
SmartBear Alumni (Retired)

Hi,

 


I've added your votes. Thanks!


 

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager



Marsha_R
Champion Level 3

Another vote please, so we can do this in keyword tests.
Manfred_F
Regular Contributor

Hi guys,



a System function for the Routine Name would be nice. We'd also Need a System function for the module Name, of course.



I'd also add my vote.



So far, You could use code templates for vbs modules and routines, which contain predefined constants for the element names, e.g. for a module:



Option Explicit

' ModulKommentar

Const mcModul = "Modulname."



or for a Routine


Function |( _

Par1, _

Par2 _

)

' KommentarFunktion

Const cRoutine = "NameFunktion"

Dim Ergebnis

  

   NameFunktion = Ergebnis

End Function



As a result, I can use the names in the log, e.g.

 



Log.Checkpoint "Tabelle Abbruch abgebrochen", mcModul & cRoutine







Regards,



Manfred

 


TanyaYatskovska
SmartBear Alumni (Retired)


Hi,


 


I've added your votes. 


Manfred, thanks for sharing your solution.


 

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager



Alice
Occasional Contributor

Please add my vote as well!

katven
New Contributor

+1 for this feature. 

 

Kindly add my vote too. 

Using TC10.50
TanyaYatskovska
SmartBear Alumni (Retired)

Hi,

Thanks for your requests! Now, we have a special place in the Community where our users can submit their ideas or vote for the ideas they like. I’ve found a similar idea that has already been submitted. You can vote it up.

http://community.smartbear.com/t5/TestComplete-Feature-Requests/have-access-to-the-name-of-the-curre...

 

 

TestComplete’s PO monitors this forum on a regular basis, and uses this information for development planning.

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager



anik_cadieux
Contributor

I am also trying to figure out a way to know the current script name. We are launching TestExecute with Bamboo using command line. I think we can use 

BuiltIn.ParamStr
meinTest
Occasional Contributor

For JavaScript, I found the following workaround. Maybe it will help others.

I create a try-catch block. Within the try I provoke an exception, this one I catch-up with the catch and read-out the function name in the stack.

 

Note: this also works across several units -> USEUNIT

function getCaller(){
  let arrStackLines = [];

  try{
    throw new Error("throw a error to get the stack");
  }catch(objE){
    arrStackLines = objE.stack.split("\n");
  }
  let strLine = arrStackLines[arrStackLines.length -1];
  let intStart = strLine.indexOf("at ") + 3;
  let intEnd = strLine.indexOf("(<");
  Log.Message(strLine.substring(intStart, intEnd));
}

 

Btw. please add my vote..:-)

 

Best regards 

 

sign.png

  meinTest GmbH

  www.meinTest.software

 

 SmartBear preferred value-added Service

 Provider in the DACH region

cancel
Showing results for 
Search instead for 
Did you mean: