Marsha_R's avatar
Marsha_R
Moderator
10 years ago
Status:
Implemented

have access to the name of the current test

This can be useful in naming objects and in custom logging.  Right now the user has to find some way to record it separately, but TestComplete already knows this name so it should be easy to expose. 

  • anuprai29's avatar
    anuprai29
    Occasional 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

  • matt_tarka's avatar
    matt_tarka
    New 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 = temp

    End Function

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear 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;