Home Case Studies Technology

Email workflow automation test

Author Image


10 Jul, 2020 · 2 min read
Article Thumbnail

End To End Test Email Wrok-flow with Cypress +Mailslurp

MailSlurp is an Email API built for developers and QA testers , let's understand step by step how we can perform email workflow integration testing with cypress :

Hope you studied about cypress on our previous blog : cypress setup

Pre-requisite : Go through how to setup cypress for your project and you have installed mailslurp-client via npm install --save mailslurp-client.

Common Test cases :

  1. test that your systems can send emails.
  2. test that your system can receive emails .
  3. test email related processes like user sign-up, password reset, newsletter subscription, transactional emails etc using real email addresses
Steps to Integrate mailslurp in your cypress project :
  • Sign up on mailslurp https://app.mailslurp.com/sign-up/ which will give you an api key.
  • Import mailslurp clent in your test/command.js :
    <code><span class="token keyword">const MailSlurp <span class="token operator">=</span> <span class="token keyword">require</span><span class="token punctuation">(</span><span class="token string">"mailslurp-client"</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token keyword">default</span><span class="token punctuation">
  • create inbox when you need in test :
    <code>mailslurp<span class="token punctuation">.<span class="token function">createInbox</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token parameter">inbox</span> <span class="token operator">=></span> <span class="token punctuation">{</span>
      <span class="token comment">// inbox = { id: '123', emailAddress: '[email protected]' }</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span></span></code>

fetch email for verification :
const emails = await mailslurp.getEmails(inbox.id);

Email responses contain a preview of an email.

<code><span class="token builtin">console</span><span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>emails<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// [ { id: '', to: [], subject: '', ...etc } ]</span></code>

Author Image