Email body validation in ATF

gowdash
Mega Guru

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 

5 REPLIES 5

Brian Bouchard
Mega Sage

Ok, here's an example using a simple Step Configuration.  The Step Configuration has 2 inputs:

u_input_sys_id is the sys_id of the notification identified in a previous step
u_input_sys_id2 is the sys_id of the change located in a previous step

 

Related code is below.

(function executeStep(inputs, outputs, stepResult, timeout) {
	
	var changeNumber;
	
	//Get the Change Request Details
	var gr = new GlideRecord("change_request");
	gr.addQuery("sys_id", inputs.u_sys_id2);
	gr.query();
	if (gr.next()) {
		//set all the vars needed to check in the notification later...
		changeNumber=gr.number.toString();
		//changeRisk=gr.risk.toString();
		
	}
	
	//Expect a line like: "Change CHG0100000 has been assigned to you."
	var stringToFind="Change " +changeNumber + " has been assigned to you.";
	
	//query the notifications for the right sys_id & the expected strings
	var gr2 = new GlideRecord("sys_email");
	gr2.addQuery('sys_id',inputs.u_sys_id );
	gr2.addQuery('body','CONTAINS',stringToFind);
	gr2.query();
	if (gr2.next()) {
		stepResult.setSuccess();
		stepResult.setOutputMessage("FOUND IT");
		return;
	}
	
	stepResult.setFail();
	stepResult.setOutputMessage("NOT SO MUCH");
	return;
	
}(inputs, outputs, stepResult, timeout));

 

Alternatively, when querying the sys_email table, you could do 1 query for just notification in question then use indexOf("SEARCH  STRING") on the body field repeatedly for each string you need to find, With that method you would be able to get a more specific output message and would potentially have less DB calls and improved performance.