cypress-gmail-tester

1.0.0 • Public • Published

cypress-gmail-tester

cypress-gmail-tester

Use Cypress E2E tests to check Gmail-based inboxes.

Usage

  1. Install using npm:
npm install --save cypress-gmail-tester
  1. Modify cypress.config.json

Create a task and call it gmail:get-messages in cypress.config.json, as shown here:

const { defineConfig } = require("cypress");
const gmailTester = require("gmail-tester");
const path = require("path");

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      on("task", {
        "gmail:get-messages": async (args) => {
          const messages = await gmailTester.get_messages(
            path.resolve(__dirname, "credentials.json"),
            path.resolve(__dirname, "token.json"),
            args.options
          );
          return messages;
        }
      });
    },
  },
});

Make sure credentials.json and token.json file are located in cypress root folder (in the same location as cypress.config.json) .More information on credentials.json and token.json can be found here.

  1. Call the task within any spec:
/// <reference types="Cypress" />

describe("Email assertion:", () => {
  it("Using gmail_tester.get_messages(), look for an email with specific subject and link in email body", function () {
    // debugger; //Uncomment for debugger to work...
    cy.task("gmail:get-messages", {
      options: {
        from: "AccountSupport@ubi.com",
        subject: "Ubisoft Password Change Request",
        include_body: true,
        before: new Date(2019, 8, 24, 12, 31, 13), // Before September 24rd, 2019 12:31:13
        after: new Date(2019, 7, 23), // After August 23, 2019
      },
    }).then((emails) => {
      assert.isAtLeast(
        emails.length,
        1,
        "Expected to find at least one email, but none were found!"
      );
      const body = emails[0].body.html;
      assert.isTrue(
        body.indexOf(
          "https://account-uplay.ubi.com/en-GB/action/change-password?genomeid="
        ) >= 0,
        "Found reset link!"
      );
    });
  });
});

Package Sidebar

Install

npm i cypress-gmail-tester

Weekly Downloads

8

Version

1.0.0

License

MIT

Unpacked Size

7.33 kB

Total Files

8

Last publish

Collaborators

  • levz0r