'Cypress crashes when test that uses gmail-tester library finished it work

I'm was trying to use "gmail-tester" library to verify the account creation message. https://www.npmjs.com/package/gmail-tester

It seems that I settled up everything as it was supposed to be done. When my test is finished I supposed to get an assertion in cypress such as this enter image description here

Instead, cypress is awaiting for a message for 30seconds enter image description here

, then browser crashes and I got this enter image description here

Does anyone know what would cause the problem?

I have managed to complete all steps mentioned in this tutorial: https://levz0r.medium.com/how-to-poll-a-gmail-inbox-in-cypress-io-a4286cfdb888

../cypress/plugins.index.js

/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
 * @type {Cypress.PluginConfig}
 */
// eslint-disable-next-line no-unused-vars

const path = require("path");
const gmail = require("gmail-tester");


module.exports = (on, config) => {
  // `on` is used to hook into various events Cypress emits
  // `config` is the resolved Cypress config

  // ...

  on("task", {
    "gmail:check": async args => {
      const { from, to, subject } = args;
      const email = await gmail.check_inbox(
        path.resolve(__dirname, "credentials.json"), // credentials.json is inside plugins/ directory.
        path.resolve(__dirname, "gmail_token.json"), // gmail_token.json is inside plugins/ directory.
        subject,
        from,
        to,
        10,                                          // Poll interval (in seconds)
        12                                           // Maximum poll interval (in seconds). If reached, return null, indicating the completion of the task().
      );
      return email;
    }
  });
};

testCase.spec.js

import Navigation from '../../../utils/navigation.spec'
import LoginPage from '../../../pageobject/login/login-page'

describe("New user registration", async function() {
    beforeEach(() => {
        cy.visit(Navigation.Login)
        
    })
    it.only("Reset Form: Email is delievered", function() {
        const test_id = new Date().getTime();
        const incoming_mailbox = `userautomatedtest+${test_id}@gmail.com`;
        // const password = uuidv1().split("-")[0];
    
        const login = new LoginPage();
        const username = "Cypress" + test_id;
        const password = "111@wZOO";

        login.registerButton()
        .usernameInput(username)
        .emailInput(incoming_mailbox)
        .firstNameInput("Name")
        .lastNameInput("Surname")
        .passwordInput(password)
        .repeatPasswordInput(password)
        .registerButton()
        //assert
        cy.contains('Registration succeeded').should('be.visible')

        cy.task("gmail:check", {
        from: "[email protected]",
        to: incoming_mailbox,
        subject: "Registration confirmation"
      })
      .then(email => {
        assert.isNotNull(email, `Email was not found`);
      });
      });
  });

btw: in documentation is mentioned that by changing this number we can manipulate awaiting time for checking email. In my case, I'm changing this value and nothing is happening.



Solution 1:[1]

This is some problem with the OAuth consent screen, probably access given is not correct, or the GMail API isn't enabled.

Solution 2:[2]

Using the most recent version of this package, I had the same issue with the plugins/index.js crashing.

I solved this by adjusting the options-parameter to match the gmail task package function check_inbox.

module.exports = (on, config) => {
  on("task", {
    "gmail:check": async (args) => {
      const { from, to, subject } = args;
      const email = await gmail.check_inbox(
        path.resolve(__dirname, "credentials.json"),
        path.resolve(__dirname, "gmail_token.json"),
        {
          subject: subject,
          from: from,
          to: to,
          wait_time_sec: 10,
          max_wait_time_sec: 30,
        }
      );
      return email;
    },
  });
};

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aditya Pandey
Solution 2 domidanke