This package provides Cypress commands to help you test email and SMS as part of end-to-end testing with Mailosaur.
npm install cypress-mailosaur --save-dev
Add the following line to cypress/support/index.js
:
import 'cypress-mailosaur'
Mailosaur commands need your Mailosaur API key to work. You can get your key via the account settings screen.
{
"env": {
"MAILOSAUR_API_KEY": "your-key-here"
}
}
You can create your own cypress.env.json
file that Cypress will automatically check. This is useful because if you add cypress.env.json
to your .gitignore
file, the values in here can be different for each developer machine.
{
"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
context('Account activation', () => {
it('should send an activation email', () => {
cy.mailosaurGetMessage('SERVER_ID', { subject: 'Activate your account' })
.then(email => {
expect(email.subject).to.equal('Activate your account');
})
.then(email => {
expect(email.attachments).to.have.lengthOf(0);
})
.then(email => {
const $body = Cypress.$(email.html.body)
const buttonText = $body.find('.button.button--green').text();
expect(buttonText).to.equal('Activate now')
})
})
})
Check out the full documentation here.
mailosaurListServers()
mailosaurCreateServer({ name })
mailosaurGetServer(serverId)
mailosaurUpdateServer(serverId, server)
mailosaurDeleteServer(serverId)
mailosaurGenerateEmailAddress(serverId)
mailosaurListMessages(serverId)
mailosaurCreateMessage(serverId)
mailosaurGetMessage(serverId, criteria)
mailosaurGetMessageById(messageId)
mailosaurSearchMessages(serverId, criteria, options)
mailosaurGetMessagesBySubject(serverId, subjectSearchText)
mailosaurGetMessagesByBody(serverId, bodySearchText)
mailosaurGetMessagesBySentTo(serverId, emailAddress)
mailosaurDeleteMessage(messageId)
mailosaurDeleteAllMessages(serverId)
mailosaurDownloadAttachment(attachmentId)
mailosaurDownloadMessage(messageId)
mailosaurGetSpamAnalysis(messageId)
serverId
- Found on the servers list within Mailosaur.server
- A valid server object.critera
- An object containing either{ sentTo: '[email protected]' }
,{ subject: 'Something' }
or{ body: 'Activate your account' }
.