Forum Discussion

Logiv's avatar
Logiv
Contributor
4 years ago
Solved

Insert variable in Project log name

Hello,

I'm sure this is simple but I can't get it to work.
I have inserted my EXE version number in a variable.
Now I want to use that variable into the log filename when I export, but I can't seem to find the right format to insert the variable.

Using Python, it would be something like this. My variable is called  VersionNumb.

 

Log.SaveResultsAs("C:\\QA\\Results\\EXE + VersionNumb.mht", lsMHT)

Thanks

  • I found the answer in a related post! Thanks.

    Log.SaveResultsAs("C:\\QA\\Result\\" + VersionNumb + ".mht", lsMHT)

4 Replies

  • Logiv's avatar
    Logiv
    Contributor

    I found the answer in a related post! Thanks.

    Log.SaveResultsAs("C:\\QA\\Result\\" + VersionNumb + ".mht", lsMHT)

  • tphillips's avatar
    tphillips
    Frequent Contributor

    Python has supported a thing called f-strings since Python 3.6. These are the recommended way to do variable substitution in strings. It will handle type conversion/interpretation for you.

     

    Before that the recommended way was to use the .format().

     

    Please avoid using string concatenation, it won't convert most types for you and is generally bad coding practice.

     

    # using f-string
    Log.SaveResultsAs(f"C:\\QA\\Result\\{VersionNumb}.mht", lsMHT)
    
    # using .format
    Log.SaveResultsAs("C:\\QA\\Result\\{0}.mht".format(VersionNumb), lsMHT)

     

     

     

     

    • Logiv's avatar
      Logiv
      Contributor

      Ok, thank you for the information.

      I didn't even know what was String concatenation until you mentioned it and I researched! I am not a programmer and my work place does not allow me to get training, so I am learning TestComplete and Python as I go.

      I checked the SmartBear help and from what I understand, it is doing a concatenation with a variable. Is it OK because it's used in a log only, or is it an older practice that is still left in the document?
      Not looking to be negative towards the help file but just trying to understand since I am pretty new to all of this. 

      def FileVersionInfoSample():
        FileName = Sys.OSInfo.WindowsDirectory + "\\notepad.exe"
        VerInfo = aqFileSystem.GetFileInfo(FileName).VersionInfo
        Log.Message("File version: " + str(VerInfo.FileMajorVersion) + "." + str(VerInfo.FileMinorVersion) + "." + str(VerInfo.FileBuildVersion) + "." + str(VerInfo.FileRevisionVersion))
        Log.Message("Description: " + str(VerInfo.FileDescription[0]))
        Log.Message("Product: " + str(VerInfo.ProductName[0]))
        Log.Message("Company: " + str(VerInfo.CompanyName[0]))




      • tphillips's avatar
        tphillips
        Frequent Contributor

        Yeah it's fine, there are many ways to do it 🙂 that way is probably most similar to the way it's done in Javascript so the implementations look the same in the docs 😉