- Mailpit works on port 8025, not 8090
- Mailpit will also need installing on you system (I've yet to look to see if I can simple include it as a dependency)
- mpGetMailsBySubject() - working
- mpFirst() - working
- mpGetHtml() - working
- mpGetText() - working
- mpDeleteAll() - working
- Simply previous refactor
- Simple refactor of mpMessageSummary to remove duplicate code
- Set a default for the Mailpit UI
- Added mpGetText() to get the text version of a message
- Increased spacing to 4
- Extensive reformatting ready for conversion to TS
- Configured a few .eslint rules for my preference
- Changed Cypress version requirement to 12+, as I want to use Cypress.command.addQuery
- Still not written any tests!
- Added mpGetHtml to get the Html version of a message
- Initial fork of the project, so that I can get Cypress to run with Mailpit, as MailHog hasn't been touched recently.
- Simple rename from 'mh...' to 'mp...' method names'
- Create a repository so that people can use any mail program they like (MailHog, Mailpit etc), and just switch out the binding
- Write proxy functions so that others can simple install it and use it as a drop-in replacement for cypress-mailhog
- Continue converting functions to mailpit
- Write tests (currently I'm writing it and using my dev project for the tests)
- ...
A collection of useful Cypress commands for Mailpit 🐗.
This package supports TypeScript out of the box.
Install this package:
# bun
bun add --dev cypress-mailpit
# npm
npm install --save-dev cypress-mailpit
# pnpm
pnpm add -D cypress-mail
# yarn
yarn add --dev cypress-mailpit
Include this package into your Cypress command file:
// cypress/support/commands
import 'cypress-mailpit';
Add the base url of your Mailpit installation in the e2e
block of your Cypress config file:
export default defineConfig({
projectId: "****",
env: {
mailpitUrl: "http://localhost:8025/",
},
});
If your Mailpit instance uses authentication, add mailpitAuth
to your Cypress env
config:
{
...
"mailpitAuth": {"user": "mailpit username", "pass": "mailpit password"}
}
or add mailpitUsername
and mailpitPassword
in Cypress env config
{
...
"mailpitUsername": "mailpit username",
"mailpitPassword": "mailpit password"
}
Yields an array of all the mails stored in Mailpit. This retries automatically until mails are found (or until timeout is reached).
cy
.mpGetAllMails()
.should('have.length', 1);
Yields an array of all mails with given subject. This retries automatically until mails are found (or until timeout is reached).
cy
.mpGetMailsBySubject('My Subject')
.should('have.length', 1);
Yields an array of all mails with given sender. This retries automatically until mails are found (or until timeout is reached).
cy
.mpGetMailsBySender('[email protected]')
.should('have.length', 1);
Yields an array of all mails with given recipient.
cy
.mpGetMailsByRecipient('[email protected]')
.should('have.length', 1);
Yields the first mail of the loaded selection.
cy
.mpGetAllMails()
.should('have.length', 1)
.mpFirst();
Deletes all stored mails from Mailpit.
cy.mpDeleteAll();
Note: the below described filter functions can be chained together to build complex filters. They are currently not automatically retrying. So make sure to either wait a certain time before fetching your mails or to implement you own re-try logic.
Filters the current mails in context by subject and returns the filtered mail list.
cy
.mpGetMailsBySender('[email protected]')
.mpFilterBySubject('My Subject')
.should('have.length', 1);
Filters the current mails in context by recipient and returns the filtered mail list.
cy
.mpGetMailsBySender('[email protected]')
.mpFilterByRecipient('[email protected]')
.should('have.length', 1);
Filters the current mails in context by sender and returns the filtered mail list.
cy
.mpGetMailsByRecipient('[email protected]')
.mpFilterBySender('[email protected]')
.should('have.length', 1);
Filters can be infinitely chained together.
cy
.mpGetAllMails()
.mpFilterBySubject('My Subject')
.mpFilterByRecipient('[email protected]')
.mpFilterBySender('[email protected]')
.should('have.length', 1);
Yields the subject of the current mail.
cy
.mpGetAllMails()
.should('have.length', 1)
.mpFirst()
.mpGetSubject()
.should('eq', 'My Mails Subject');
Yields the body of the current mail.
cy
.mpGetAllMails()
.should('have.length', 1)
.mpFirst()
.mpGetBody()
.should('contain', 'Part of the Message Body');
Yields the sender of the current mail.
cy
.mpGetAllMails()
.should('have.length', 1)
.mpFirst()
.mpGetSender()
.should('eq', '[email protected]');
Yields the recipient of the current mail.
cy
.mpGetAllMails()
.should('have.length', 1)
.mpFirst()
.mpGetRecipients()
.should('contain', '[email protected]');
Yields the list of all file names of the attachments of the current mail.
cy
.mpGetAllMails()
.should('have.length', 1)
.mpFirst()
.mpGetAttachments()
.should('have.length', 2)
.should('include', 'sample.pdf');
Asserts if there is a mail with given subject.
cy.mpHasMailWithSubject('My Subject');
Asserts if there is a mail from given sender.
cy.mpHasMailFrom('[email protected]');
Asserts if there is a mail to given recipient (looks for "To", "CC" and "BCC").
cy.mpHasMailTo('[email protected]');
Waits until more then <moreMailsThen
> mails are available on Mailpit.
This is especially useful when using the mpFilterBy<X>
functions, since they do not support automatic retrying.
// this waits until there are at least 10 mails on Mailpit
cy
.mpWaitForMails(9)
.mpGetAllMails()
.mpFilterBySender("[email protected]")
.should("have.length", 1);
Navigate into the test-server
directory.
cd ./test-server/
Install dependencies.
composer install
yarn # or npm install
Start docker server.
docker-compose up
Open the test page in your browser: http://localhost:3000/cypress-mp-tests/
Open Mailpit in your browser: http://localhost:8025/
Open the Cypress testclient.
yarn cypress:open