Write Test results to file !

I'm testing an application. There are many test cases. I've created one script for one test case. I'd like to write test result to .txt file and one test result file for one one script also. I've tried to use LogError function but it just shows log in Running script window.

Could you please help me or give me the examples?

Thanks so much !

Comments

  • Look at chapter 14 in the senseTalk reference. It will tell you more than you wanted to know :wink:
  • FHQWHGADS wrote:
    Look at chapter 14 in the senseTalk reference. It will tell you more than you wanted to know :wink:
    I want to write my script results into .txt file, but I don't know how to put my variables into .txtfile. e g, my script is as follow:
    --start
    put the time into startTime
    (*my script code*)
    put the time into stopTime

    --how can I put startTime,stopTime into .txt file?

    set file "/tmp/testresult.txt" to {{
    startTime
    stopTime
    }}
    -- it seems doesn't work!
    --end

    pls help me, thanks.
  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    The code you've shown should work to create a file, although it will contain the words "startTime" and "stopTime" rather than the values you want. One way to write the start and stop time values would be like this:
    set file "/tmp/testresult.txt" to startTime & return & stopTime
    
    Another approach would be to use the merge function to substitute the values:
    set file "/tmp/testresult.txt" to merge of {{
    [[startTime]]
    [[stopTime]]
    }}
    
    Does that help?
  • The code you've shown should work to create a file, although it will contain the words "startTime" and "stopTime" rather than the values you want. One way to write the start and stop time values would be like this:
    set file "/tmp/testresult.txt" to startTime & return & stopTime
    
    Another approach would be to use the merge function to substitute the values:
    set file "/tmp/testresult.txt" to merge of {{
    [[startTime]]
    [[stopTime]]
    }}
    
    Does that help?


    Thanks, they both work well.
  • The code you've shown should work to create a file, although it will contain the words "startTime" and "stopTime" rather than the values you want. One way to write the start and stop time values would be like this:
    set file "/tmp/testresult.txt" to startTime & return & stopTime
    
    Another approach would be to use the merge function to substitute the values:
    set file "/tmp/testresult.txt" to merge of {{
    [[startTime]]
    [[stopTime]]
    }}
    
    Does that help?

    I do not know how to append text for a file
    code:
    if file "/tmp/testresult.txt" exists then
    open file "/tmp/testresult.txt" for appending
    --then how to append text
    else
    create file "tmp/testresult.txt"
    --how
    end if

    Does it necessary to close the file after appending your context, and how?
  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    The simple way to append to a file is just to treat it as a container and use the "put ... after" command:
    put newResult & return after file "/tmp/testresult.txt"
    
    Using the open file command, here is the code that will do the same thing:
    open file "/tmp/testresult.txt" for appending
    write newResult & return to file "/tmp/testresult.txt"
    close file "/tmp/testresult.txt"
    
    Using this approach, you could open the file at the beginning of your script, then use write commands at various points to write additional results to the file, and finally close the file at the end of your script run. This may be slightly more efficient since the "put ... after" command will open and close the file each time, but unless your result file is very large I don't think the difference will be noticeable.
  • The simple way to append to a file is just to treat it as a container and use the "put ... after" command:
    put newResult & return after file "/tmp/testresult.txt"
    
    Using the open file command, here is the code that will do the same thing:
    open file "/tmp/testresult.txt" for appending
    write newResult & return to file "/tmp/testresult.txt"
    close file "/tmp/testresult.txt"
    
    Using this approach, you could open the file at the beginning of your script, then use write commands at various points to write additional results to the file, and finally close the file at the end of your script run. This may be slightly more efficient since the "put ... after" command will open and close the file each time, but unless your result file is very large I don't think the difference will be noticeable.

    Thank you very much, I like the second approach better, it's more efficient.

    I have another question, how can I create a file using a variable as it's name, the code:
    --the code
    put "filename" into fname
    put ".txt" after fname
    create file "/tmp/fname" --It doesn't work and encounter an error
    --end

    how can I create a file using the variable fname as it's name, thanks.
  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    First you'll want to set fname to the full pathname of the file. You can construct the name in a variety of ways, such as concatenating the folder, file name and extension using the "&" operator, or with the "put before" and "put after" commands. Or you can use a template with double square brackets with the merge function if you like:
    set fname to merge("/tmp/[[filename]].txt")
    
    Then, all you have to do to create the file is put something into it. Or, to use the "open file ... for appending" approach, you can create the file first like this:
    create file fname
    
    You might want to check whether it already exists first:
    if there is no file fname then create file fname
    
    Good luck! :)
  • Thanks a lot!

    It works well.
  • Hi, is there any function that can get remote system's(system under test) info and memory, I want to write it to result file. Thanks!

    SystemInfo() and SystemVersion() can only get local system info.
Sign In or Register to comment.