Wednesday, 29 May 2024

PowerShell script to attach cucumber report and send email by running .ps1 file

Save below code as .ps1 file

# How to run .ps1 from command line ? 
# powershell.exe -ExecutionPolicy Bypass -File qa-smoke-newman.ps1
$sendMailFromE1 = @{
    From = 'AutomationTeam@email.com'
    Subject = 'RegressionTests(API) | Soap, Rest | Cucumber/RestAssured Automation Results | QA Lab'
    Body = "Hi Team, `nPlease find the attached Cucumber automation report for Soap and Rest Regression Test results in QA lab.
        `nThank you`n Automation Team"
    SmtpServer = 'smtp-xy.mycompany.com'
}
# Define arrays of email addresses for "To" recipients
$toRecipients = @(
    'all-engineering-xyzproduct@mycompany.com',
'pochampalli.itlabs@mycompany.com'
)
#Define arrays of email addresses for "CC" recipients
$ccRecipients = @(
    'member1@mycompany.com',
'member2@mycompany.com',
)
# Define the attachment paths
$attachments = @(
    'C:\APIAutomation\target\cucumber-reports\api-cucumber-report.html'
)
Send-MailMessage -To $toRecipients -Cc $ccRecipients -Attachments $attachments @sendMailFromE1


To run this .ps1 file use below java code in cucumber, selenium framework. 
How to run power shell script file in selenium cucumber AfterAll hook using JVM shutdown method How to run power shell script file in selenium cucumber AfterAll hook using JVM shutdown method 

No comments:

Post a Comment