ruffainn
ruffainn

Reputation: 101

How can I acess content of email triggered by a test in Cypress

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)

Upvotes: 3

Views: 6896

Answers (4)

anichols
anichols

Reputation: 74

There are various 3rd party solutions that provide real email addresses you can access via an API. These come with plugins for Cypress that can help you with exactly this scenario. See here: https://docs.cypress.io/plugins#email

Some also offer SMTP servers which is useful in staging or dev environments so all email gets captured in them and you don't send external emails.

Our company uses Mailosaur to test both of the scenarios you mention, password reset and email validation during account creation but of course you can use others mentioned here too.

Upvotes: 1

Julien Bras
Julien Bras

Reputation: 19

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!

Upvotes: 1

Martin van Driel
Martin van Driel

Reputation: 1867

  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.

Upvotes: 6

Krishna Majgaonkar
Krishna Majgaonkar

Reputation: 1746

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

Upvotes: 1

Related Questions