Jump to content

How to generate an html report for each test case


 Share

Recommended Posts

Here is some source code for you to modify in order to make it as complicated as you can make it.

Local $sFileName = "A_Report.html"
Local $sReportText = "Report:-" & @CRLF & _
        "Test 1/ Passed" & @CRLF & _
        "Test 2/ Failed" & @CRLF & _
        "Test 3/ Failed"
;ConsoleWrite( $sReportText & @LF) ; Un-comment this line and see output in Output window of SciTE. (Toggle "F8" key when in SciTE.)

Local $sName = _HtmlReport($sFileName, $sReportText)
;ConsoleWrite($sName & @LF)
ShellExecute($sName) ; Opens HTML file with default web browser.


Func _HtmlReport($sFileName, $sReport)
    Local $Source = _
            '<html>' & @CRLF & _
            '<body>' & StringReplace($sReport, @LF, "<BR>") & _
            '</body>' & @CRLF & _
            '</html>'
    ;ConsoleWrite($Source & @LF)

    ; ----- Increment file name (No duplicate file names) -----
    Local $iNum = 1
    While FileExists($sFileName)
        Sleep(10)
        $sFileName = StringRegExpReplace($sFileName, "(?i)^([^\.]+?)(?:_?\d*)(\.html?)", "\1_") & $iNum & StringRegExpReplace($sFileName, "(?i)^([^\.]+?)(?:_?\d*)(\.html?)", "\2")
        $iNum += 1
    WEnd
    ; -------> End of Increment file name ----------

    FileWrite($sFileName, $Source)
    Return $sFileName
EndFunc   ;==>_HtmlReport
Link to comment
Share on other sites

Malkey, sometimes you're really scary  :D

Local $sFileName = "A_Report"
Local $sReportText = "Report:-" & @CRLF & _
        "Test 1/ Passed" & @CRLF & _
        "Test 2/ Failed" & @CRLF & _
        "Test 3/ Failed"
Local $sName = _HtmlReport($sFileName, $sReportText)
ShellExecute($sName)

Func _HtmlReport($sFileName, $sReport)
    Local $Source = _
            '<html>' & @CRLF & _
            '<body>' & StringReplace($sReport, @LF, "<BR>") & _
            '</body>' & @CRLF & _
            '</html>'

    Local $newfile = @scriptdir & "\" & $sFileName & ".html"
    Local $iNum = 1
    While FileExists($newfile) 
       $iNum += 1
       $newfile = @scriptdir & "\" & $sFileName & " (" & $iNum & ").html"
    Wend
    FileWrite($newfile, $Source)
    Return $newfile
EndFunc   ;==>_HtmlReport
Edited by mikell
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...