【问题标题】:Test Complete : How to know the test function name, test file name and project name from within a test complete function测试完成:如何从测试完成函数中知道测试函数名称、测试文件名和项目名称
【发布时间】:2014-06-11 00:13:21
【问题描述】:

我们正在尝试执行一个测试函数,我们需要知道测试函数的名称、当前文件的名称和当前项目的名称。

类似

function TestGlobalSearchClientContacts(){
 var this_function_name = ??
 var this_file_name = ??
 .
 .
 .
 testcode 

}

使用 Test Complete 时如何做到这一点? 我们使用的是 JScript,TC 版本是 9

【问题讨论】:

    标签: automated-tests jscript testcomplete


    【解决方案1】:

    要获取项目名称,请使用:

    aqFileSystem.GetFileNameWithoutExtension(Project.FileName)
    

    要获取当前函数名,可以调用这个函数:

    function getCurrentFunctionName() {
      return arguments.callee.caller.toString().match(/function\s+([^\s\(]+)/)[1];
    }
    

    要获取当前单元名称,您需要将测试作为测试项运行。然后你可以使用:

    function getCurrentUnitName() {
      return Project.TestItems.Current.ElementToBeRun.Caption.match(/Script\\([^ ]+) -/)[1];
    }
    

    如果您在测试中打开Log.CallStackSettings.EnableStackOn... 设置,您还可以在测试日志的“调用堆栈”选项卡中查看单元和函数名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-02
      • 2016-09-12
      • 1970-01-01
      • 2013-01-27
      • 2016-01-20
      • 1970-01-01
      • 2014-09-21
      • 2015-12-08
      相关资源
      最近更新 更多