- 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;
- 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
- 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
- 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
- Marsha_RModerator
Hi Tanya -
- 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;
I would like all of those options! All of them can be useful in constructing an object name or logging messages. Tell R&D I don't want to pick just one. ;)
- TanyaYatskovskaSmartBear Alumni (Retired)Status added:New Idea
- ekiza23Contributor
I would also suggest to get some 'call stack'; at least the direct caller of the current routine, and if possible N (or all) the call stack levels available.
- MKozinetsStaffStatus changed:New IdeatoSelected for Development
We will investigate if we can implement this suggestion in the upcoming release. We will update this thread with the results. Thank you.
- AerlockOccasional Contributor
Being able to reference the current test as an object would be helpful too. For example I am currently writing a bunch of new automation tests and find myself reusing several steps/tests with Code Expressions in them. These Code Expressions almost always reference the current Keyword Test using the KeywordTests.<TestName>.Variables.<Variable> format. Since I am copy/paste-ing these steps from test to test I frequently forget to go back and adjust my Code Expressions so I'll have one test trying to evaluate a value from a completely different test. Having a ThisTest.Variables.<Variable> object instead, so that when I copy/paste from one test to another I don't have to go in and fix it would be a BIG help.
- sunilbabuOccasional Contributor
Any update on this?
Related Content
- 10 years ago
- 7 years ago
- 9 years ago