cypress-gmail-tester
v1.0.0
Published
Verify emails with Cypress!
Downloads
188
Maintainers
Readme
cypress-gmail-tester
Use Cypress E2E tests to check Gmail-based inboxes.
Usage
- Install using
npm
:
npm install --save cypress-gmail-tester
- 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.
- 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: "[email protected]",
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!"
);
});
});
});