1

An email is being sent in my case ( 1. When resetting the password, 2. Adding a New member) during both API and UI tests. How can I access these emails without actually logging into my mail manual and accessing the content, so I can add them to the test and verify?

The test is something like the below.

  1. User can reset the password.
  2. Mail is triggered.
  3. User uses the link in the mail to reset the password.
  4. User logs in again using the new password.

Second test.

  1. Admin adds a member.
  2. Admin adds a new member and gets a mail about confirmation.
  3. verify the mail sent to the new member's email.

Would appreciate any help here.

I have tried to look into the third parties but it seems I need to use their email accounts I was hoping if someone can help me regarding Gmail(accessing the content of emails going to Gmail)

Sadeed_pv
  • 513
  • 1
  • 9
  • 22
ruffainn
  • 83
  • 1
  • 14
  • There are a few 3rd party plugins that can allow Cypress to work with emails. https://docs.cypress.io/plugins/directory#Email – jjhelguero Jul 27 '22 at 15:42
  • Thanks but it seems most of them are paid, I was hoping if there is some other ways to do it or a free third party? – ruffainn Jul 29 '22 at 19:59
  • 1
    Find an email server that dumps emails to folders/files (e.g., [smtp-dump](https://github.com/snsttr/smtp-dump) and have your tests look for/read the files there. – Heretic Monkey Jul 29 '22 at 23:45

3 Answers3

3
  1. If your application is running locally and is sending the emails directly through an SMTP server, you can use a temporary local test SMTP server running inside Cypress. Read the blog post "Testing HTML Emails using Cypress" for details.
  2. If your application is using a 3rd party email service, or you cannot stub the SMTP requests, you can use a test email inbox with an API access. Read the blog post "Full Testing of HTML Emails using SendGrid and Ethereal Accounts" for details.

Taken from the official best practice page at "Verifying sent emails". Read more here.

Martin van Driel
  • 1,397
  • 2
  • 12
  • 20
  • will this above work for Gmail, asking as I am doing this for the first time. – ruffainn Aug 16 '22 at 11:03
  • @ruffainn I'm not sure how you run the tests. Can you give a bit more context? Are you able to send the email to a different inbox or service during the test? – Martin van Driel Aug 16 '22 at 13:23
  • We run a test on the test server, certain actions trigger emails and emails associated with the user. In this case, the user has Gmail so a mail will be sent to Gmail., I need to access and verify the content of that mail. – ruffainn Aug 16 '22 at 14:08
  • I use the fake-smtp-server node module which creates a smtp server and then point my test app to the local fake smtp server. This server doesn't actually forward any messages it receives but displays them in a web interface where you can then point cypress for tests. – Mihai Aug 18 '22 at 09:44
  • Seems like a good idea but i need to run them on a different environment and not just on local sever – ruffainn Aug 19 '22 at 17:03
2

To check if an email have been correctly sent by your application in a Cypress E2E test, you can use an external service like TestSendr.

This (free) service will allow you to send an email to something ending by @testsendr.link, and then check the email received via a simple REST API. Check the quick start!

1

If you are looking for a free third-party email client (of course with just 100 emails per month) you can use testmail.app

This app is pretty much basic and easy to integrate with cypress. You can find docs here

Krishna Majgaonkar
  • 1,532
  • 14
  • 25