Forum Discussion

ChrisPro's avatar
ChrisPro
Contributor
11 years ago

Path of the current executed script

In Jscript, i would like to know the current path of script. 



For-example, the script TEST.sj is executed and i would like to add a fonction in "TEST.sj" returning the path of the script "TEST.sj"
  • AlexKaras's avatar
    AlexKaras
    Icon for Champion Level 3 rankChampion Level 3
    Hi Chris,



    Does something like this (VBScript) help?

    IIRC, to get the name of the current routine that function must be called with the 'Current' parameter (i.e. GetScriptFileName('Current'))




    '-------------------------------------------------------------------------------

    Function GetScriptFileName(ByVal CurrentScriptName)

      Dim Project_Name, ProjectRoutinesIteratorObject, _

        ScriptRoutineObject, File_Name


      GetScriptFileName = ""



      ' Get the name of the current project

      Project_Name = ChangeFileExt(ExtractFileName(Project.FileName), "")



      ' Get the routines iterator of the current project

      Set ProjectRoutinesIteratorObject = Sys.OleObject(_

        "TestComplete.TestCompleteApplication", _

        "").Integration.ProjectRoutinesIterator(Project_Name)



      ' Iterate through the list of routines to find the routine with the

      ' specified name

      Call ProjectRoutinesIteratorObject.Reset()

      While (ProjectRoutinesIteratorObject.HasNext())

        Set ScriptRoutineObject = ProjectRoutinesIteratorObject.Next

        If (CurrentScriptName = ScriptRoutineObject.Name) Then

          File_Name = ScriptRoutineObject.ScriptFileName

        End If

      Wend



      GetScriptFileName = File_Name

    End Function

    '-------------------------------------------------------------------------------