The CreatorCon Call for Content is officially open! Get started here.

How to use the Automated Test Framework to test Email Notifications?

Joey Day
Giga Guru

How can I write a test case in the Automated Test Framework to assert whether an e-mail notification has been sent? I have some ideas for how to script it, but has the community already settled on any best practices for this?

1 ACCEPTED SOLUTION

Hi

I went to a ServiceNow Developer meetup last night where a senior technical consultant from ServiceNow did a deep dive into ATF.  His advice was to use gs.sleep to put waits in to wait for any asynchronous updates, one of the example he gave was when checking if an email had been generated in sys_email table, so sounds like you're on the money 🙂

cheers

Bonnie

View solution in original post

4 REPLIES 4

Erik Stolberg
Tera Guru

I would probably just query the sys_email table with filter type=sent and instance=((GlideRecord generating email))

Yeah, this is what I had kind of settled on, but this particular e-mail notification is event-based, so I think it takes it several milliseconds (maybe even several seconds) to propagate through the system (and in this case, I don't even care if it's `sent` or not, it can be `send-ready` and I'll consider that a pass). Is there a way to introduce a delay before a test step? Is that advisable? I don't want to have delays built into thousands of tests to the point where running our whole regression test suite takes multiple days. Haha.

EDIT: I introduced a 10-second delay (using gs.sleep(10000)). The test now passes. I still wonder if this is advisable though. Is there a better, more reliable way to do this?

Hi

I went to a ServiceNow Developer meetup last night where a senior technical consultant from ServiceNow did a deep dive into ATF.  His advice was to use gs.sleep to put waits in to wait for any asynchronous updates, one of the example he gave was when checking if an email had been generated in sys_email table, so sounds like you're on the money 🙂

cheers

Bonnie

Thanks, Bonnie!