Forum Discussion

georgereynolds's avatar
georgereynolds
Occasional Contributor
8 years ago
Solved

aqEnvironment.GetEnvironmentVariable fail

I have a script which uses the following line

 

 

  HOMEPATH = aqEnvironment.GetEnvironmentVariable("HOMEPATH")

 

This fails the script (i.e. the files do not get deleted as they should per the script).

 

I will add that this works fine in Testcomplete12 on my desktop - but on the server running TestExecute12 it fails and it outputs the Log.Error message

 

If I replace it with the hardcoded path, it works

 

  HOMEPATH = "C:\users\builduser\"

 

 

 

Full script is below - any suggestions why this occurs?

 

Sub DeletePDFFiles
  ms = 5000
  HelpStr = "Delaying script for " & ms & "milliseconds."
  aqUtils.Delay ms, HelpStr
  
  Dim spath, spath2, HOMEPATH
  HOMEPATH = aqEnvironment.GetEnvironmentVariable("HOMEPATH")
  sPath1 = HOMEPATH & "\Downloads\ClaimForm*"
  sPath2 = HOMEPATH & "\Downloads\xxx_UK_xx_xx_xx_T_And_C_2016*"
  cPath1 = HOMEPATH & "\Downloads\ClaimForm.pdf"
  cPath2 = HOMEPATH & "\Downloads\xxx_UK_xx_xx_xx_T_And_C_2016.pdf"
  If aqFileSystem.Exists(cPath1) Then
    Log.Message "Claim Form Doc Found!"
    aqFileSystem.DeleteFile(sPath1)
If Not aqFileSystem.Exists(cPath1) Then Log.Message "ClaimForm Doc Deleted" Else Log.Error "ClaimForm NOT Deleted" End if Else Log.Error "Claim Form Doc NOT Found!" End if If aqFileSystem.Exists(cPath2) Then Log.Message "T&C Doc Found!" aqFileSystem.DeleteFile(sPath2) If Not aqFileSystem.Exists(sPath2) Then Log.Message "T&C Doc Deleted" Else Log.Error "T&C Doc NOT Deleted" End if Else Log.Error "T&C Doc NOT Found!" End if End Sub

 

  • I've fixed this as I echoed HOMEPATH and realised it didn't include "C:\"  (it was just "users\builduser\") so I added that in and it works now!

     

4 Replies

  • What is HOMEPATH when it succeeds and when it fails?

    What error do you get when it fails?  On which script line?

     

    • georgereynolds's avatar
      georgereynolds
      Occasional Contributor

      joseph_michaud 

      The control moves straight to the else part of the code. I've added debug now to test what that environment variable resolves to - it might be a setup issue on the server.

       

  • It looks as though there may be an issue in your message?

     

     

    HOMEPATH = "C:\users\builduser\"

    sPath1 = HOMEPATH & "\Downloads\ClaimForm*"

     

    Doesn't sPath1 resolve out to: "C:\users\builduser\\Downloads\ClaimForm*"

     

    Is there a double slash in the file path that's causing the problem?

    • georgereynolds's avatar
      georgereynolds
      Occasional Contributor

      I've fixed this as I echoed HOMEPATH and realised it didn't include "C:\"  (it was just "users\builduser\") so I added that in and it works now!