Write start, end and total time testcase runing into file

Hi All,

What I want is to create log file which give me start time, end time and how many minutes it takes, and I want to add it in my code below. Please help.

put (["print" testcase1], ["print" testcase2], ["print" testcase3]) into mytestcase
repeat with each testcase of mytestcase
try
get print(testcase)
put testcase & ";Passed" into reportLine
catch error
put testcase & ";Failed" & error.reason into reportLine
end try
end repeat

Comments

  • Here is what I tried but no luck. Got error "STInvalidNumberException. Value is not a number: starttime". Please help....!
    +++++++++++++++++++++++++++++++
    if there is a file "~buffalo/Desktop/Kiosk8_log" then
    delete file "~buffalo/Desktop/Kiosk8_log"
    end if

    create file "~buffalo/Desktop/Kiosk8_log"

    put (["print" testcase1], ["print" testcase2], ["print" testcase3]) into mytestcase
    repeat with each testcase of mytestcase
    try
    put the time into starttime
    get print(testcase)
    put the time into currenttime
    put currenttime - starttime into total

    open file "~buffalo/Desktop/Kiosk8_log" for appending
    put testcase & ": " & starttime & " " & currenttime & " " & total into file "~buffalo/Desktop/Kiosk8_log"
    close file "~buffalo/Desktop/Kiosk8_log"
    put testcase & ";Passed" into reportLine

    catch error
    put testcase & ";Failed" & error.reason into reportLine
    end try
    end repeat
    +++++++++++++++++++++
    In addition, how do I concat the date and time into file name. I've tried "~buffalo/Desktop/Kiosk8_log" & "_" & the date & "_" & the time, but it creates whole the date folder, time folder and file with second.


    Best Regards
  • EggplantMattEggplantMatt ForumAdmin admin
    You can get the start time, end time, and time to run like this:
    // result logs are tab delimited, so...
    [color=black]set the itemDelimiter to tab[/color]
    // store the contents of the latest log file in a variable
    // for ease of use
    [color=black]put file( the logfile of the last item of scriptResults(testcase) ) into theLog[/color]
    // extract the start time
    [color=black]put time(the first item of the first line of theLog) into startTime[/color]
    // convert it to a format that includes the seconds
    [color=black]convert startTime to long time[/color]
    // extract the end time
    [color=black]put time(the first item of the last line of theLog) into endTime[/color]
    // convert it to a format that includes the seconds
    [color=black]convert endTime to long time[/color]
    // extract the execution time (which is already calculated in the log)
    [color=black]put the third word of the last item of the last line of theLog into executionTime[/color]
    
    Hope that helps.
  • EggplantMattEggplantMatt ForumAdmin admin
    buffalokml wrote:
    In addition, how do I concat the date and time into file name. I've tried "~buffalo/Desktop/Kiosk8_log" & "_" & the date & "_" & the time, but it creates whole the date folder, time folder and file with second.

    This happens because the date format uses slashes and the time format uses colons, both of which are folder delimiters in Mac OS X. You'll need a couple of steps to reformat the date and time before appending them to your file name:
    [color=black]set the clockFormat to "24hour"[/color] // so we don't have to bother with AM/PM
    [color=black]put the date into myDate
    replace every occurrence of "/" with "" in myDate
    put the time into myTime
    replace every occurrence of ":" with "" in myTime
    create file "~buffalo/Desktop/Kiosk8_log" & "_" & myDate & "_" & myTime[/color]
    
  • Matt,

    Thanks so much for your responded. But I am unable to make it work. After I let it ran successfully testcase1 and then I stop. I got no error. the Kiosk8_Log file is created, but it empty. Please see below

    if there is a file "~buffalo/Desktop/Kiosk8_log" then
    delete file "~buffalo/Desktop/Kiosk8_log"
    end if

    create file "~buffalo/Desktop/Kiosk8_log"

    put (["print" testcase1], ["print" testcase2], ["print" testcase3]) into mytestcase
    repeat with each testcase of mytestcase
    try
    get print(testcase)
    // result logs are tab delimited, so...
    set the itemDelimiter to tab
    // store the contents of the latest log file in a variable
    // for ease of use
    put file( the logfile of the last item of scriptResults(testcase) ) into theLog
    // extract the start time
    put time(the first item of the first line of theLog) into startTime
    // convert it to a format that includes the seconds
    convert startTime to long time
    // extract the end time
    put time(the first item of the last line of theLog) into endTime
    // convert it to a format that includes the seconds
    convert endTime to long time
    // extract the execution time (which is already calculated in the log)
    put the third word of the last item of the last line of theLog into executionTime

    open file "~buffalo/Desktop/Kiosk8_log" for appending
    put testcase & ": " & startTime & " " & endTime & " " & executionTime into file "~buffalo/Desktop/Kiosk8_log"
    close file "~buffalo/Desktop/Kiosk8_log"
    put testcase & ";Passed" into reportLine

    catch error
    put testcase & ";Failed" & error.reason into reportLine
    end try
    end repeat
  • EggplantMattEggplantMatt ForumAdmin admin
    You're going to have to help me out a little here. What does the print function do? What value does it return?

    You're executing the print handler as you create your list, so the list is a list of the return values from the handler. What does that look like? Please do a
    put mytestcase
    
    after the line where you create the list and post the output so I can see what you are iterating over.

    It would probably be helpful if you posted the entire "print" script as well.

    It appears that the testcase iterator must not contain the name of a script, which is what scriptResults() is expecting, so you're probably not getting any values back from that, which is why your file is empty.
  • EggplantMattEggplantMatt ForumAdmin admin
    buffalokml wrote:
    Here is what I tried but no luck. Got error "STInvalidNumberException. Value is not a number: starttime". Please help....!
    put the time into starttime
    get print(testcase)
    put the time into currenttime
    put currenttime - starttime into total

    And what you want to use here is "the seconds", not "the time". When you need to display the value of starttime, you'll want to do either:
    convert starttime to long time
    
    or
    put time(starttime)
    
    so that you're displaying something you can read and not just the number of seconds since the start of the Unix epoch. And when you want to output "total", you'll also want to convert that from raw seconds to something more readable. I'm attaching a script that will do that for you.
  • Matt,
    Here we go. The printing is the file name. I did put mytestcases right after I create the list below, there is nothing display/return

    *************************

    if there is a file "~buffalo/Desktop/kiosk8_log" then
    delete file "~buffalo/Desktop/kiosk8_log"
    end if
    create file "~buffalo/Desktop/kiosk8_log"
    repeat 8 times
    put (["Printing" testcase61], \
    ["Printing" testcase62], \
    ["Printing" testcase63]) into mytestcases
    put mytestcases
    set the strictProperties to true
    repeat with each testcase of mytestcases
    try
    get Printing.(testcase)
    set the itemDelimiter to tab
    put file( the logfile of the last item of scriptResults(testcase) ) into theLog
    put time( the first item of the first line of theLog) into startTime
    convert startTime to long time
    put time(the first item of the last line of theLog) into endTime
    convert endTime to long time
    put the third word of the last item of the last line of theLog into executionTime
    open file "~buffalo/Desktop/kiosk8_log" for appending
    write testcase & ":" & " " & startTime & " " & endTime & " " & executionTime to file "~buffalo/Desktop/kiosk8_log" at end
    close file "~buffalo/Desktop/kiosk8_log"
    put testcase & "; Passed" into reportLine
    catch error
    put testcase & ";Failed; " & error.reason into reportLine
    end try
    end repeat
    add 1 to myloop
    put "Printing iteration is" & " " & myloop
    end repeat
    function testcase61
    put failed into testfailed
    put passed into testpassed
    wait 60 // add a 1-minute delay between testcases
    ["ComonShare" FindWelcomeScreen]
    (* if ["ComonShare" FindWelcomeScreen] is true then
    put the time into starttime
    end if *)
    if imagefound(enterusernamescreen) then
    ["ComonShare" PrintLogin]
    else
    set reporterror = "Testcase61 is failed at login"
    LogError reporterror
    return testfailed & reporterror
    exit function
    end if
    put ((mainprintbutton, mainscreen), (documentvaultbutton, docstored), \
    (kiosktiff, selectvaultdocscreen), (vaultselectdocbutton, selectvaultdocscreen), \
    (printdocbutton, printdocscreen), \
    (continuetransactionbutton, howtopayfortransactionscreen), \
    (iagreebutton, acceptagreementscreen), (nothanksbutton, printedreceiptscreen), \
    (logoutimdonebutton, printtaskcompleted)) into mytestcaseimages
    repeat with each item of mytestcaseimages
    if ["ComonShare" FindCurrentScreenAndPressButton: it] is false then
    set reporterror = "Testcase61 is failed at " & " " & it
    LogError reporterror
    return testfailed & reporterror
    exit function

    end if
    end repeat

    return testpassed

    end testcase61


    function testcase62
    put failed into testfailed
    put passed into testpassed
    wait 60 // add a 1-minute delay between testcases
    ["ComonShare" FindWelcomeScreen]
    if imagefound(enterusernamescreen) then
    ["ComonShare" PrintLogin]
    else
    set reporterror = "Testcase62 is failed at login"
    LogError reporterror
    return testfailed & reporterror
    exit function
    end if
    put ((mainprintbutton, mainscreen), (documentvaultbutton, docstored), \
    (kioskpdf, selectvaultdocscreen), (vaultselectdocbutton, selectvaultdocscreen), \
    (printdocbutton, printdocscreen), \
    (continuetransactionbutton, howtopayfortransactionscreen), \
    (iagreebutton, acceptagreementscreen), (nothanksbutton, printedreceiptscreen), \
    (logoutimdonebutton, printtaskcompleted)) into mytestcaseimages

    repeat with each item of mytestcaseimages
    if ["ComonShare" FindCurrentScreenAndPressButton: it] is false then
    set reporterror = "Testcase62 is failed at " & " " & it
    LogError reporterror
    return testfailed & reporterror
    exit function
    end if
    end repeat
    return testpassed

    end testcase62
    ******************************
  • EggplantMattEggplantMatt ForumAdmin admin
    buffalokml wrote:
    Here we go. The printing is the file name. I did put mytestcases right after I create the list below, there is nothing display/return
    That's going to be your first problem -- if the list you create is empty, then there's nothing to iterate over, so nothing will get written to your file.
    buffalokml wrote:
    put (["print" testcase1], ["print" testcase2], ["print" testcase3]) into mytestcase
    
    Do you understand that the function calls that you are putting in the list above are being executed as the list is created? So the list is not going to contain the text you see above, but the return values of those function calls. If calling this:
    put ["print" testcase1]
    
    doesn't produce any output, then there won't be a value in your list for that entry. I think you actually want to create your list like this:
    put (testcase61, testcase62, testcase63) into mytestcase
    
    Since these testcases do not appear to be individual scripts, but rather functions within a single script, you can forget about the code I supplied to get the timing -- that only works if these are individually executed scripts.

    I've gone back and looked at your original code for the timing:
    put the time into starttime 
    get print(testcase) 
    put the time into currenttime 
    put currenttime - starttime into total
    
    There's actually no reason that this shouldn't be working or that it would throw an exception. My suggestion of using "the seconds" instead of the time and then converting after the calculation is a viable workaround, but it shouldn't be necessary. Which version of Eggplant are you running? (You can find that by going to Eggplant > About Eggplant.)
Sign In or Register to comment.