Email body validation in ATF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2019 05:27 AM
Dear Experts,
We are automating the test cases for change management using ATF [London]. One of the requirement is to validate the email body. We are able to validate the emails for recipients but not the body.
Please shed some light if you have implemented the above in your instances. Thanks!
Best Regards,
Gowdash

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2019 05:32 AM
What is it that you aren't able to check? We look for particular strings in the Body and Subject fields of the notification.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2019 05:37 AM
Hi Brain,
For example, if I want to validate the below email body from outbound emails, the values will be populated dynamically. Is there a way to validate this from email logs using ATF?
Change: ${URI_REF}
Opened: ${opened_at}
Initiator/Contact: ${opened_by}/${initiator_contact}
Risk: ${risk}
CR Type: ${cr_type}
Start Date: ${planned_start)
End Date: ${planned_end)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2019 07:47 PM
I ran a simplified test of what you're talking about and it should be very doable. Here's my test:
Step 1, run a record query that gets the change_request recordyou're looking for.
Step 2, run a record query that gets the sys_email record you're looking for.
Step 3, run a server side script that
a. queries the change_request record from Step 1 and gets all the pertinent fields that will be in the notification and places them into variables in the script. For example, get the Risk value and store it into a var called "risk"
b. queries the notification_request record from Step 2, but also adding to the query things like...
addQuery('body',CONTAINS','Risk: ' +risk);
You can get really specific with the format here, by looking for an exact match to the body, or you can be a little more generic like I was here by simply asking if the body contains a simple string. I like this format because it's easier to read and its testing what matters most to me - is the right data there. If the format gets changed for some reason but the core data is still there, i'm happy to let the test pass at this point. Perhaps when we get more savvy with ATF we'll find a better way, but this works for now.
I can share more specifics about my test if you'd like, but I'm heading home for the night and will need to do it in the morning when I get back in the office.
Hope that at least gives you something to think about...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2019 12:24 AM
Hey Brian,
Thanks a lot! This is a positive sign for me. However, the code below is not working. The test step is failing always. Please share a sample code if you have.
function(outputs, steps, stepResult, assertEqual) {
// add test script here
var changeID = '64930169dbc57300daf9e1bb4b9619bc'; // record id from the submit a change step
var emailID = 'a4930169dbc57300daf9e1bb4b9619cf'; // record id from open sys_email form step
var stat = "";
var changeRec = new GlideRecord('change_request');
changeRec.addQuery('sys_id',steps(changeID).request_id);
changeRec.query();
if(changeRec.hasNext())
{
stat = changeRec.state;
cat = changeRec.category;
}
var emailRec = new GlideRecord('sys_email');
emailRec.addQuery('sys_id',steps(emailID).request_id);
//emailRec.addQuery('body','CONTAINS','State: ' +stat);
if(emailRec.hasNext())
{
return true;
}
else
{
return false;
}
})(outputs, steps, stepResult, assertEqual);
Best Regards,
Gowdash