Forum Discussion

JackSparrow's avatar
JackSparrow
Frequent Contributor
9 years ago

Function[Python] For creating an HTML Report

Am also looking for this type of HTML reporting actually i need some more help since am new to everything, after checking the code which i found in our Community itself i.e https://community.smartbear.com/t5/TestComplete-General-Discussions/Creating-html-reports/m-p/129285#M23885]

 

Sub PageHeader(resfile)

Call aqFile.WriteToTextFile(resfile, "<html>", aqFile.ctUnicode)
Call aqFile.WriteToTextFile(resfile, "<head>", aqFile.ctUnicode)
Call aqFile.WriteToTextFile(resfile, "<title> Automation Results </title>", aqFile.ctUnicode)
Call aqFile.WriteToTextFile(resfile, "</head>", aqFile.ctUnicode)
Call aqFile.WriteToTextFile(resfile, "<body>", aqFile.ctUnicode)
Call aqFile.WriteToTextFile(resfile, "<table width=90% border=2 bordercolor=" & "#000000 id=table1  bordercolorlight=" & "#000000>", aqFile.ctUnicode)

End Sub


Sub AddHtml_Results(resfile,Value)


Call aqFile.WriteToTextFile(resfile, "<tr>", aqFile.ctUnicode)
Call aqFile.WriteToTextFile(resfile, "<td width=80%  bgcolor = #000000  >", aqFile.ctUnicode) 

Call aqFile.WriteToTextFile(resfile, value, aqFile.ctUnicode)

Call aqFile.WriteToTextFile(resfile, "</td>", aqFile.ctUnicode)
Call aqFile.WriteToTextFile(resfile, "</tr>", aqFile.ctUnicode)
Call aqFile.WriteToTextFile(resfile, "</table>", aqFile.ctUnicode)

End Sub

Sub PageFooter(resFile)

Call aqFile.WriteToTextFile(resfile, "</body>", aqFile.ctUnicode)
Call aqFile.WriteToTextFile(resfile, "</html>", aqFile.ctUnicode)

End Sub

Actually what exactly we need to give in the test case for the values resFile and Value , can you please let me know

8 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    The code didn't originate with me so I'm just guessing...

     

    BUT... resfile, as I read the code, is the FQN of the output file for the html report. e.g., C:\\reportfiles\\myreport.html.  Obviously, you want to do things a LITTLE bit smarter like build the file name based upon date and time for the report output... but hopefully you get the idea.

    As for value, I believe that is specifically the text that you want to be added as a record to the table. Now, you can add that text specifically and explicitly yourself OR you could write code to parse out the native log file and dump that to your HTML. Either way, value is your ACTUAL result text you want to show up in the file.

     

    That's my best guess, at least...

    Keep in mind, also, that the code you pasted is VBScript so you'll have to do the necessary syntax changes for it to be formatted for Python.

    • JackSparrow's avatar
      JackSparrow
      Frequent Contributor

      tristaanogre thanks for the info

       

      if am not wrong this how in python the code looks like

      def PageHeader(resfile):
         aqFile.WriteToTextFile(resfile, "<html>", aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "<head>", aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "<title> Automation Results </title>", aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "</head>", aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "<body>", aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "<table width=90% border=2 bordercolor=" & "#000000 id=table1  bordercolorlight=" & "#000000>", aqFile.ctUnicode)
        return
      
      
      
      def AddHtml_Results(resfile,Value):
        
         aqFile.WriteToTextFile(resfile, "<tr>", aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "<td width=80%  bgcolor = #000000  >", aqFile.ctUnicode) 
         aqFile.WriteToTextFile(resfile, value, aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "</td>", aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "</tr>", aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "</table>", aqFile.ctUnicode)
         return
      
       
      
      def PageFooter(resFile):
         aqFile.WriteToTextFile(resfile, "</body>", aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "</html>", aqFile.ctUnicode)
         return
      

       Do i Need to maintain all those header then middle of html and footer separately cant we merge all the 3 things into single function.

    • JackSparrow's avatar
      JackSparrow
      Frequent Contributor

      And after the Execution the Report is looking like this

       

       

      anyone can give me guidance on this

       

      and code which i used is

      def Reporting(resfile,Value):
         aqFile.Create("C:\\work\\myreport.html")
         aqFile.WriteToTextFile(resfile, "<html>", aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "<head>", aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "<title> Automation Results </title>", aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "</head>", aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "<body>", aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "<table width=90% border=2 bordercolor=" + "#000001 id=table1  bordercolorlight=" + "#000001>", aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "<tr>", aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "<td width=80%  bgcolor = #000000  >", aqFile.ctUnicode) 
         aqFile.WriteToTextFile(resfile, Value, aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "</td>", aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "</tr>", aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "</table>", aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "</body>", aqFile.ctUnicode)
         aqFile.WriteToTextFile(resfile, "</html>", aqFile.ctUnicode)
         
         
      
      def testcas1():
      
        Reporting("C:\\work\\myreport.html",'Hello Reporting')

       

      • baxatob's avatar
        baxatob
        Community Hero

        Your code works fine :)

         

        This is what I see:

         

        Possibly you need to add a tag to control the color of the font.

         

        P.S. Imho building report like you do - is a very very fragile way. Imagine that sometime you will require more complex grid.