Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
cypress-mailosaur
Advanced tools
Extends Cypress' cy commands that let you integrate email and SMS testing into your continuous integration process.
Using Cypress and Mailosaur together you can:
Mailosaur is a service that lets you automate email testing (e.g. email verification, password resets, etc.) and SMS testing (e.g. one-time passwords).
Mailosaur also provides dummy SMTP servers to test with; allowing you to catch email in staging environments - preventing email being sent to customers by mistake.
Follow these steps to start testing email with Cypress:
Install the Mailosaur commands via npm
or yarn
:
npm i -D cypress-mailosaur
# or
yarn add -D cypress-mailosaur
Once downloaded, add the following line to cypress/support/e2e.js
(or cypress/support/index.js
in older versions of Cypress) to import the commands into your Cypress project:
require('cypress-mailosaur');
Mailosaur commands need your Mailosaur API key to work. You can learn about managing API keys here.
cypress.config.js
module.exports = defineConfig({
env: {
MAILOSAUR_API_KEY: "your-key-here",
},
// ...
});
To set the environment variable on your machine, it needs to be prefixed with either CYPRESS_
or cypress_
.
export CYPRESS_MAILOSAUR_API_KEY=your-key-here
For this example, we'll navigate to a password reset page, request a new password link (sent via email), and get that email.
Create a new test spec:
touch cypress/e2e/password-reset.cy.js
Now edit the file to something like this:
describe('Password reset', () => {
const serverId = 'abcd1234'
const serverDomain = 'abcd1234.mailosaur.net'
const emailAddress = 'password-reset@' + serverDomain
it('Makes a Password Reset request', () => {
cy.visit('https://github.com/password_reset')
cy.title().should('equal', 'Forgot your password?')
cy.get('#email_field').type(emailAddress)
})
it('Gets Password Reset email from Mailosaur', () => {
cy.mailosaurGetMessage(serverId, {
sentTo: emailAddress
}).then(email => {
expect(email.subject).to.equal('Reset your password');
passwordResetLink = email.text.links[0].href;
})
})
it('Follows the link from the email', () => {
const validPassword = 'delighted cheese jolly cloud'
cy.visit(passwordResetLink)
cy.title().should('contain', 'Change your password')
cy.get('#password').type(validPassword)
cy.get('#password_confirmation').type(validPassword)
cy.get('form').submit()
})
})
You can test pretty much anything with Mailosaur and Cypress, including:
For more information, check out the full Mailosaur docs for the most up-to-date guides and troubleshooting tips.
Mailosaur Team, Premium, and Ultimate customers can perform SMS tests with Cypress, whilst Trial account users can just ask support to enable this feature to try it out!
SMS testing works in just the same way as email testing above. However rather than dealing with email addresses, you search using phone numbers instead. For example:
cy.mailosaurGetMessage(serverId, {
sentTo: '447555111222'
}).then(sms => {
expect(sms.text.body).to.equal('Your OTP code is: 123456')
})
Install all development dependencies:
cd test/react-app
npm i
cd ../../
npm i
The test suite requires the following environment variables to be set:
export CYPRESS_MAILOSAUR_API_KEY=your_api_key
export CYPRESS_MAILOSAUR_SERVER=server_id
Run all tests:
npm test
You can get us at support@mailosaur.com
FAQs
Extends Cypress' cy commands that let you integrate email and SMS testing into your continuous integration process.
The npm package cypress-mailosaur receives a total of 82,767 weekly downloads. As such, cypress-mailosaur popularity was classified as popular.
We found that cypress-mailosaur demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.