Is there a way to get the current script name?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2010
10:29 AM
02-23-2010
10:29 AM
Is there a way to get the current script name?
I'm looking for a way to get the current script name that is being executed. I can't seem to figure this out in the help file nor in the forum search. Any guidance to this problem is appreciated.
Steve
Steve
7 REPLIES 7
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2010
05:14 PM
02-23-2010
05:14 PM
Hello Steve,
As far as I understand, you want to get the name of the routine that is currently running. There's no built-in functionality to do this. However, you can do this by using native JScript mechanisms. Here's the getStack function that returns the routine name by using the current call stack:
BTW, when using the Log.Error method, TestComplete posts call stack information on the Call Stack page of the test log. You can find more information in the Log.Error help topic.
As far as I understand, you want to get the name of the routine that is currently running. There's no built-in functionality to do this. However, you can do this by using native JScript mechanisms. Here's the getStack function that returns the routine name by using the current call stack:
function test1()
{
Log.Error("Error X in " + getStack());
}
function getStack()
{
var cur = getStack.caller;
var callers = new Array();
while(cur)
{
callers.push(cur.toString().match(/function (\w*)/)[1]);
cur = cur.caller;
}
return callers.join("\r\n");
}
BTW, when using the Log.Error method, TestComplete posts call stack information on the Call Stack page of the test log. You can find more information in the Log.Error help topic.
--
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2010
05:16 PM
02-23-2010
05:16 PM
Thanks for the reply David. I'm actually looking to find the current script name (e.g., test_columns.sj). Is that possible?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2010
07:16 PM
02-23-2010
07:16 PM
Hello Steve,
There's no way to do this. I suggest that you add a global variable to a script unit and assign the file name of the current unit to the variable. After that, you can use this variable in the unit as you want. Here's an example:
There's no way to do this. I suggest that you add a global variable to a script unit and assign the file name of the current unit to the variable. After that, you can use this variable in the unit as you want. Here's an example:
var ScriptName = "test_columns.sj";
function Main()
{
Log.Message("The name of the currently running script file is '" + ScriptName + "'");
...
}
--
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2010
09:48 AM
02-25-2010
09:48 AM
Sadly, I tried getting the name from the RootLogData.dat, but I found out later, it does not appear in the Log Folder until you either pause, abort, or finish the script execution. It seems to hold onto the log in memory and dump them to files.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2010
05:23 AM
09-14-2010
05:23 AM
I know this is an older thread, but I am using this to grab the script name and append it to my log files...
var strFullPathToScript = Project["FileName"];
var strScriptName = Utilities.StringReplace(Utilities.ExtractFileName(strFullPathToScript),".mds","",1);
var strFullPathToScript = Project["FileName"];
var strScriptName = Utilities.StringReplace(Utilities.ExtractFileName(strFullPathToScript),".mds","",1);
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2010
11:36 AM
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2019
06:18 AM
07-12-2019
06:18 AM
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)); }
Best regards
meinTest GmbH
SmartBear preferred value-added Service
Provider in the DACH region
