Test case which validates the days between start date and end date in an Incident to be 10 using ATF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 08:34 AM
Hi,
Can you please help me with the ATF test steps that can find the difference between the start date and end date in an Incident, and validate that the difference is 10? Kindly help.
Regards
Suman P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2024 01:19 AM
hi @Community Alums
It could only be done through Run Server-side script step.
Paste the below script with required modification of fields/table:
(function() {
// Replace with your actual Incident record's sys_id
var incidentSysId = 'YOUR_INCIDENT_SYS_ID';
// Query the incident record
var gr = new GlideRecord('incident');
if (gr.get(incidentSysId)) {
// Get the start_date and end_date fields
var startDate = gr.getValue('start_date'); // Adjust this field name if different
var endDate = gr.getValue('end_date'); // Adjust this field name if different
// Convert to GlideDateTime for date calculations
var startDateTime = new GlideDateTime(startDate);
var endDateTime = new GlideDateTime(endDate);
// Calculate the difference in days
var differenceInMillis = endDateTime.getNumericValue() - startDateTime.getNumericValue();
var differenceInDays = differenceInMillis / (1000 * 60 * 60 * 24);
// Validate the difference is 10 days
if (differenceInDays !== 10) {
gs.addErrorMessage('The difference between start_date and end_date is not 10 days. Actual difference: ' + differenceInDays + ' days.');
return false; // Fail the test step
} else {
gs.addInfoMessage('The difference between start_date and end_date is exactly 10 days.');
return true; // Pass the test step
}
} else {
gs.addErrorMessage('Incident record not found.');
return false; // Fail the test step
}
})();
Kindly let me know if it works or not. 🙂
*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.
*************************************************************************************************************
Regards
Shaqeel
***********************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.
***********************************************************************************************************************
Regards
Shaqeel