Official ProxiedMail plugin for email testing with Cypress. This library is using the base NodeJS library of ProxiedMail.
- Creating a new email address
- Receiving letter contents that were sent to generated emails
- Receiving subject, body, html, headers of email
In this example, we're creating the email address and receiving the first mail. Also, we're asserting that the subject and body are correct.
describe('template spec', () => {
it('testing email', {
defaultCommandTimeout: 10000,
}, () => {
cy.proxiedmail().then((proxiedmail) => {
cy.visit('https://proxiedmail.com')
cy.get('.nav_li').contains('Sign up').click()
cy.url().should('include', '/en/signup')
cy.then(
() => {
return new Promise(resolve => {
proxiedmail.createProxyEmail(proxyEmail => {
resolve(proxyEmail)
})
})
}).then((proxyEmail) => {
cy.wrap(proxyEmail.getId()).as('proxyEmailId')
cy.wrap(proxyEmail.getProxyEmail()).as('emailAddress')
})
Cypress.on('uncaught:exception', (err, runnable) => {
// returning false here prevents Cypress from
// failing the test
return false
})
cy.then(function () {
global.proxyEmailId = this.proxyEmailId
cy.get('#login').type(this.emailAddress)
cy.get('#password').type('123456')
return cy.get('#proceed').click()
})
cy.then(() => {
return new Promise(resolve => {
const interval = setInterval(() => {
proxiedmail.getReceivedEmails(global.proxyEmailId, (resp) => {
if (resp.data.length > 0) {
resp.data[0].getDetails(function (details) {
clearInterval(interval);
resolve(details)
})
}
})}, 3000);
return interval;
})
},
{
timeout: 10000
}
).then(details => {
expect(details.getSubject()).to.equal('Please confirm your email on ProxiedMail')
expect(details.getPayloadBodyHtml()).to.have.string(
'please confirm that you want to receive messages by clicking'
);
});
});
})
})
- API Documentation
- ProxiedMail JS Client
- This client on npm
- ProxiedMail
- Email testing with Cypress in ProxiedMail Blog
- Email testing with Cypress on Medium
Ensure you have Cypress installed first then run:
npm install --save-dev cypress-test-email
Then include the plugin in your cypress/support/index.{js,ts} file.
import 'cypress-test-email'
It's necessary to specify your API token in PROXIEDMAIL_API_KEY
.
You can configure this plugin by putting to env variable PROXIEDMAIL_API_KEY
to cypress.config.js
const { defineConfig } = require("cypress");
module.exports = defineConfig({
"env": {
"PROXIEDMAIL_API_KEY": "YOUR API KEY"
},
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
You can also pass the variable in a command line
PROXIEDMAIL_API_KEY=your-api-key cypress run
You can obtain API key by signing up on ProxiedMail. Basic usage of the product is free up to 10 mailboxes + some API limits. If you want to get the best result please think about upgrading your account.
See pricing on ProxiedMail
ProxiedMail requires timeouts in order to get your emails. Please adjust the timings where you have the email testings up to 10s (1000ms).
The Cypress ProxiedMail plugin provides one simple command attached to the Cypress object: cy.proxiedmail(). This method returns a ProxiedMail client instance that has all the same methods and properties as the official ProxiedMail client. Use the command with the then() method to access the instance:
describe('sign up using disposable email', function () {
it('can set config', () => {
//<gen>cy_config_dynamic
cy.proxiedmail().then((proxiedmail) => {
// use the proxiedmail instance
});
})
});
cy.then(
() => {
return new Promise(resolve => {
proxiedmail.createProxyEmail(proxyEmail => {
resolve(proxyEmail)
})
})
})
cy.then(() => {
return new Promise(resolve => {
const interval = setInterval(() => {
proxiedmail.getReceivedEmails(global.proxyEmailId, (resp) => {
if (resp.data.length > 0) {
resp.data[0].getDetails(function (details) {
clearInterval(interval);
resolve(details)
})
}
})
}, 3000);
return interval;
})
},
{
timeout: 10000
}
).then(details => {
expect(details.getSubject()).to.equal('Please confirm your email on ProxiedMail')
expect(details.getPayloadBodyHtml()).to.have.string(
'please confirm that you want to receive messages by clicking'
);
});
If you have any questions or need help, please contact us on ProxiedMail or you can use pmjshelp@pxdmail.com.
Good luck!