Jump to content
Sign in to follow this  
narasimha

How to generate an html report for each test case

Recommended Posts

narasimha

Hi All,

I am new to Autoit Forum

How to generate " HTML "report to each testcase as pass or fail based on successful or unsuccessful.Please suggest and guide me.If anyone has already implemented then can you share source code?

 

Share this post


Link to post
Share on other sites
Malkey

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

Share this post


Link to post
Share on other sites
mikell

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

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.