Skip to content

How do I insert a screenshot captured within the test into the Email Body

This example demonstrates how to insert a screenshot with the email Body while implementing compose and distribution of an email from within the context of an automated test in execution.

Worksoft SaaS is agnostic to the purpose these emails serve in the context of your business, be it a notification of a positive outcome or a negative outcome.

In this example, first the sender is set, then the subject, recipient list (to, cc, bcc), followed by the email body, and finally, the email is distributed. For email body, a simple text string is used. In real life, the email body usually is not that simple where static text satisfies your needs. Please refer to other examples that cover techniques that will help you build email bodies incrementally, including multi-part mime types (embedding screenshots, attaching files, etc).ly, including multi-part mime types (embedding screenshots, attaching files, etc).

Solution:

# Command Target Value
To begin the email service block
1 emailBlockStart    
To set the sender for the composed email
2 setSender info@eureqatest.com  
To set the subject for the composed  email
3 setSubject Worksoft SaaS Notification: Issue identified  
To set the ‘To’ recipient list for the composed email
4 setRecipientToList recipient1@gmail.com  
To set the ‘CC’ recipient list for the composed email
5 setRecipientCCList recipient2@gmail.comrecipient3@gmail.com  
To set the ‘BCC’ recipient list for the composed email
6 setRecipientBCCList recipient4@gmail.com  
To create the email body with a variable name
7 createBody body_template  
To create an email body part from Text or HTML string
8 createBodyPartFromTextOrHTML Hi <mention recipient’s name here>, 
<mention your body text here>
body_template
To get the instruction id for the first failed instruction
9 getIdentifierForFirstFailedInstruction screenshotid  
To create the email body part from the screenshot captured within the test run
10 createBodyPartFromScreenshot ${screenshotid} body_part1
To append the body part to the email body
11 appendBodyPartToBody
body_part1
body_template  
To send the composed email to the sender’s specified in “To, CC and BCC” list
12 sendEmail    
It indicates the end of the email block
13 emailBlockEnd    


Tips, Tricks, Gotchas & Best Practices:
  

  • The subject can be foreign language characters
  • You can also use CSS styles like underlines, font color, and to highlight anything important in bold letters and the table background color in the email body to make the email look effective.

Representative Usage Scenarios for this Example:

Use Case #1:

Consider an e-commerce site https://www.amazon.com, add 5 or more products into the cart, verify the count of products in the shopping bag, proceed to checkout, add shipping details and complete payment method and then try to place an order.

In the above process, there are certain cases like

1. Products may or may not add into the cart
2. Product may available or may not available or out of stock
3. The payment process may successful or unable to process the payment details
4. The Order may be placed or may not be placed

If the user wants to capture all the above-mentioned cases w/ relevant details like product name, order number, payment details, etc.., an email can be customized using these commands and sent to the user using the email commands. This email can be customized in such a way that the screenshot will be embedded within the email body.

Feedback and Knowledge Base