Forum Discussion
- tristaanogreEsteemed ContributorACTUALLY... if you're using JScript, you can use the technique discussed in the following article:
http://blog.smartbear.com/post/11-02-16/improving-traceability-in-testcomplete-logs/
Every function you create, then, add in the code as the first line of the functioneval(Project.Variables.functionEnter)
You then make sure you have a project variable set as a string type with the default value set tovar functionName = eval ('arguments.callee.toString()');
var parameters = eval ('arguments.callee.toString()');
var message = '';
functionName = functionName.substr('function '.length);
functionName = functionName.substr(0, functionName.indexOf('('));
parameters = parameters.substr (parameters.indexOf ('(') + 1);
parameters = parameters.substr (0, parameters.indexOf (')'));
parameters = parameters.replace (/\r\n|\n/gm, ' ');
parameters = parameters.split(/,\s?/);
for (var i = 0; i < parameters.length; i++)
{
message += 'Parameter [' + parameters + '] : ';
message += typeof arguments + '\n';
if (arguments === undefined)
{
message += '\n';
}
else if (typeof arguments === "string")
{
message += '\t"' + arguments + '"\n\n';
}
else
{
message += '\t' + arguments + '\n\n';
}
}
Log.Message ('Entering ' + functionName, message);
This works like a charm and I've started using this extensively in my own code work. - alevans4Contributor
ACTUALLY... if you're using JScript, you can use the technique discussed in the following article:
http://blog.smartbear.com/post/11-02-16/improving-traceability-in-testcomplete-logs/
I'm a little confused with that blog post. Specifically where he says, "JScript doesn’t have some sort of macro expand or #include feature to
aid in calling this code, but we can use a feature that TestComplete
does have—project variables." While true, Jscript doesn't have includes, TestComplete definitely does (USEUNIT), unless you took it away in v8 since we're still on v7. And if you're able to use project variables, you're definitely also able to use includes since you're running in TestComplete. So, just have standard include script, or multiple depending on your needs.
Add this somewhere in your script (or like I do in a standard include):Function.prototype.name = function() {
var m = this.toString().match(/^\s*function\s+([^\s\(]+)/);
return m ? m[1] : "";
}
then in whatever test you run:function test()
{
Log.Message(argument.callee.name());
}
If you're squirrelly about modifying the Function prototype, could just drop a generic function:function getFunctionName(fn)
{
var m = fn.toString().match(/^\s*function\s+([^\s\(]+)/);
return m ? m[1] : "";
}
and thenfunction test()
{
Log.Message(getFunctionName(argument.callee));
}
Adding in the extra parameter info would be fairly trivial if you wanted to drop in something like a Function.prototype.logFunctionCall or something. - Manfred_FRegular ContributorHi 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
- YMinaevStaffHi,
There is no built-in way to do this. However, we have an appropriate suggestion to implement such an ability, and your post has increased its rating. - I add my voice for this feature.
- YMinaevStaffHi,
I've increased the suggestion's rating. - ory_zContributorCan I add another vote?
Thanks. - YMinaevStaffHi,
Your vote is added. - my vote too :-(
- Hi Regalo,
Done. The suggestion's rating is increased.
Related Content
- 2 years ago
- 11 months ago
- 11 months ago
Recent Discussions
- 24 hours ago
- 2 days ago