Forum Discussion

JamesG's avatar
JamesG
New Contributor
3 months ago
Solved

Emailing Summary Report

Hi all,

I have got some python code to create and send an email with an attachment after each test run and it works perfectly.

I would now like to add the 'Test Execution Summary'  the the email but cant figure out how to get hold of it or locate it.

Has anyone done this or know how I can locate the correct summary ?

thanks

J.

 

  • JamesG's avatar
    JamesG
    3 months ago

    Thanks Rraghvani, I am not using outlook, I am using this code to attach the summary ( the 'Summary.htm' is the test file I was using - 

       # Attach test report file
        attachment_path = 'C:\\Users\\JamesG\\Documents\\Summary.htm'
        with open(attachment_path, "rb") as attachment:
            part = MIMEApplication(attachment.read(), Name="test_report.pdf")
            part["Content-Disposition"] = f'attachment; filename="{attachment_path}"'
            msg.attach(part)

     

    This works but I cant find or figure out how to find the 'Test Execution Summary' for the current run ?

     

4 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    If using Outlook, then it's not possible to send this report. The report contains various code that gets rejected by Outlook due to security issues.

    However, you can use TestComplete Command Line with /ExportSummary and provide a link to the location of the summary report in your email. Or, use /ExportLog to parse and convert the information to be shown in an email like,

     

    • JamesG's avatar
      JamesG
      New Contributor

      Thanks Rraghvani, I am not using outlook, I am using this code to attach the summary ( the 'Summary.htm' is the test file I was using - 

         # Attach test report file
          attachment_path = 'C:\\Users\\JamesG\\Documents\\Summary.htm'
          with open(attachment_path, "rb") as attachment:
              part = MIMEApplication(attachment.read(), Name="test_report.pdf")
              part["Content-Disposition"] = f'attachment; filename="{attachment_path}"'
              msg.attach(part)

       

      This works but I cant find or figure out how to find the 'Test Execution Summary' for the current run ?

       

      • JamesG's avatar
        JamesG
        New Contributor

        Sorted it.

        Log results with this - 

        Log.SaveResultsAs("C:\\Users\\JamesG\\Documents\\", lsHTML, 1)

         

        Send with this

        import smtplib
        from email.mime.multipart import MIMEMultipart
        from email.mime.text import MIMEText
        from email.mime.application import MIMEApplication


        def send_email():
            # Email configuration
            smtp_server = '****'
            smtp_port = **
            sender_email = '******@*****.co.uk'
            sender_password = "**********"
            recipient_email = '*****.*******@********.co.uk'
            subject = "Test Report"
            body = "Test Complete has finished."
            
                

            # Create a multipart message
            msg = MIMEMultipart()
            msg["From"] = sender_email
            msg["To"] = recipient_email
            msg["Subject"] = subject

            # Add body to email
            msg.attach(MIMEText(body, "plain"))
            
            # Attach test report file
            attachment_path = 'C:\\Users\\JamesG\\Documents\\Summary.htm'
            with open(attachment_path, "rb") as attachment:
                part = MIMEApplication(attachment.read(), Name="test_report.pdf")
                part["Content-Disposition"] = f'attachment; filename="{attachment_path}"'
                msg.attach(part)

                  
            # Connect to SMTP server and send email
            
            server = smtplib.SMTP(smtp_server, smtp_port)
            server.starttls()
            server.login(sender_email, sender_password)
            server.send_message(msg)
            server.quit()