- anuprai29Occasional Contributor
Hi,
You can use this method to get current running script name, but scipt should be running from Project TestItem page.
Project.TestItems.Current.ElementToBeRun.Caption
- chrisbRegular Contributor
You can do it in Javascript like this...
ProjectSuite.Variables.currentTestName = arguments.callee.toString().match(/function ([^\(]+)/)[1];
See http://stackoverflow.com/questions/280389/how-do-you-find-out-the-caller-function-in-javascript
- matt_tarkaNew Contributor
Here's a function that I developed. It forces TestComplete to create a test log.
As far as I can tell....
Testcomplete will not generate a log before finishing a test or pausing a test. Without having a log available, finding the current keyword test name is difficult - TestComplete doesn't have a built-in method - Asking TC to save a log forces it to generate a log - the log will contain the current test name (really whatever caused the runner to start. It could be a keywork test, test item, script, etc.).
Once you have create the file from a log export, you can open the file and extract the name that will appear in the test log.
Function GetCurrentTestName()
dim temp
dim logfolderPath
dim logindexFile
dim indexPathFile
dim templogPath
dim templogfile
dim templogText'delete previous folder
Call aqFileSystem.DeleteFolder(Project.ConfigPath + "\ExportedLog", true)
'testcomplete will not generate a log before finishing a test or pausing a test.
'Without having a log available, finding the current keyword test name is
'difficult - TestComplete doesn't have a built-in method - Asking TC to
'save a log forces it to generate a log - the log will contain the
'current test name
log.SaveResultsAs Project.ConfigPath + "ExportedLog\templog.xml", IsXML
Set templogfile = aqFile.OpenTextFile(Project.ConfigPath + "ExportedLog\templog.xml", aqFile.faRead, aqFile.ctANSI)
templogText = templogfile.ReadAll
templogfile.Close
'<Prp name="test type" type="S" value="Log_Index_check7777"/>
dim iFind1
dim iFind2
dim iFind3
dim sText1
dim sText2
sText1 = "<Prp name=" + chr(34) + "test type" + chr(34) + "type=" + chr(34) + "S" + chr(34) + ""
iFind1 = InStr(templogText, "test type")
sText2 = "value="
iFind2 = InStr(iFind1+1, templogText, sText2)
iFind3 = InStr(iFind2+1, templogText, "/>")
temp = Mid(templogText,iFind2 + len(sText2)+1, iFind3 - iFind2 - len(sText2)-2)
log.message "current test name: '" + Mid(templogText,iFind2 + len(sText2)+1, iFind3 - iFind2 - len(sText2)-2) + "'"
GetCurrentTestName = tempEnd Function
- TanyaYatskovskaSmartBear Alumni (Retired)
Hi Marsha,
Thanks for your suggestion.
Our R&D team liked it, and they requested some additional info. Could you please clarify what name do you want to get?
- the name of the currently executed script routine;
- the name of the current script unit;
- the name of the current KDT test;
- the name of the current test item;
Related Content
- 9 years ago
- 7 years ago
- 9 years ago