Reputation: 105
I want to trigger a outlook mail when I run a batch of automations cases through UFT 12.50. I want to create 2 tables in the email. 1 table giving information of the number of passed and failed cases and the 2nd table giving information about all the failed cases.
I am using the below code for this and the creation of 1st table is fine. For the 2nd table I will have to traverse through a list containing all the failed cases using either for each or for loop.
But when I try to include the VB script under html, UFT is throwing the error attached in screen shot.
Please let me know if there is other way to create tables for an outlook email using VB Scripting. And also please let me know how to include for loops inside a html in UFT.
Below is the code snippet:
[Dim oOutlook, oEmail, vEmailTo
vEmailTo = "[email protected]"
execDate = Day(Date) & "/" & Month(Date) & "/" & Year(Date) & " Time: " & Hour(Now) & ":" & Minute(Now) & ":" & Second(Now)
passCount = 10
totalCount = 30
abortCount = 10
failCount = 10
passPercent = round((passCount/totalCount)*100)
dim myList
Set myList = CreateObject("System.Collections.ArrayList")
myList.Add("a")
myList.Add("b")
myList.Add("c")
vEmailSubject = "Test Automation report for execution on: " & execDate
Set oOutlook = CreateObject("Outlook.Application")
Set oEmail = oOutlook.CreateItem(0)
oEmail.To = vEmailTo
oEmail.Subject = vEmailSubject
oEmail.Attachments.Add("D:\AutomationTestReport_14-9-2015-15-20-21.html")
oEmail.HTMLBody = "<HTML>"&_
"<p style=font-size:12pt;font-family:Calibri>Hi Team,</p>"&_
"<p style=font-size:12pt;font-family:Calibri> </p>"&_
"<p style=font-size:12pt;font-family:Calibri>Below is the automation test suite result for the execution on " & Day(Date) & "/" & Month(Date) & "/" & Year(Date) & ".</p>"&_
"<p style=font-size:12pt;font-family:Calibri> </p>"&_
"<p style=font-size:12pt;font-family:Calibri> </p>"&_
"<TABLE BORDER=5 BORDER-COLOR=BLACK WIDTH=100% CELLPADDING=4 CELLSPACING=3>"&_
"<TR>"&_
"<TH COLSPAN=5><BR><H3><p style=font-size:25pt;font-family:Calibri><strong>Automation Test Result</strong></p></H3>"&_
"</TH>"&_
"</TR>"&_
"<TR>"&_
"<TH><p style=font-size:15pt;font-family:Calibri>TOTAL COUNT</p></TH>"&_
"<TH><p style=background-color:green;font-size:15pt;font-family:Calibri>PASS</p></TH>"&_
"<TH><p style=background-color:red;font-size:15pt;font-family:Calibri>FAIL</p></TH>"&_
"<TH><p style=background-color:red;font-size:15pt;font-family:Calibri>ABORTED</p></TH>"&_
"<TH><p style=font-size:15pt;font-family:Calibri>PASS PERCENTAGE</p></TH>"&_
"</TR>"&_
"<TR ALIGN=CENTER>"&_
"<TD><p style=font-family:Calibri>" & totalCount & " </p></TD>"&_
"<TD><p style=font-family:Calibri>" & passCount & " </p></TD>"&_
"<TD><p style=font-family:Calibri>" & failCount & " </p></TD>"&_
"<TD><p style=font-family:Calibri>" & abortCount & " </p></TD>"&_
"<TD><p style=font-family:Calibri>" & passPercent & " </p></TD>"&_
"</TR>"&_
"</TABLE>"&_
"<p style=font-size:12pt;font-family:Calibri> </p>"&_
"<p style=font-size:12pt;font-family:Calibri> </p>"&_
"<TABLE BORDER=5 WIDTH=100% CELLPADDING=4 CELLSPACING=3>"&_
"<TR>"&_
"<TH COLSPAN=5><BR><H3><p style=font-size:25pt;font-family:Calibri><strong>Test Cases Failed</strong></p></H3>"&_
"</TH>"&_
"</TR>"&_
"<SCRIPT LANGUAGE=""VBScript"">"&_
<!--
Function CanDeliver(Dt)
CanDeliver = (CDate(Dt) - Now()) > 2
End Function
-->
"</SCRIPT>"&_
"</HTML>"
wait 2
oEmail.Send
wait 2
Set oEmail = Nothing
Set oOutlook = Nothing][1]
Upvotes: 0
Views: 2273
Reputation: 49455
Did you try to debug the code? Do you get any errors?
Where and when do you run the script?
Only Internet Explorer browsers may run such code and create an instance of the Application class. If you pasted it into the message body - Outlook applied strict rules to script and doesn't allow to run unsafe code. So, your code can be disabled simply.
Also please remember that Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.
Upvotes: 2