Skip to content

Latest commit

 

History

History
209 lines (169 loc) · 6.08 KB

README.md

File metadata and controls

209 lines (169 loc) · 6.08 KB

ProxiedMail Cypress Plugin

Official ProxiedMail plugin for email testing with Cypress. This library is using the base NodeJS library of ProxiedMail.

Features

  • Creating a new email address
  • Receiving letter contents that were sent to generated emails
  • Receiving subject, body, html, headers of email

Example

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'
        );
      });
    });
  })
})

Quick links

Install

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'

Configuration

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

Obtaining API key

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

Timeouts

ProxiedMail requires timeouts in order to get your emails. Please adjust the timings where you have the email testings up to 10s (1000ms).

Usage

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
        });
    })
});

Common methods

createProxyEmail

        cy.then(
            () => {
                return new Promise(resolve => {
                    proxiedmail.createProxyEmail(proxyEmail => {
                        resolve(proxyEmail)
                    })
                })
    })

getReceivedEmails

        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'
        );
    });

Help

If you have any questions or need help, please contact us on ProxiedMail or you can use pmjshelp@pxdmail.com.

Good luck!