cypress-social-logins: Error: module not found: "ws" from file ..... node_modules/puppeteer/lib/WebSocketTransport.js

  • Library Version: Screen Shot 2020-02-06 at 3 34 36 PM

  • OS: MacOS v 10.14.6

  • Node.js Version: v10.15.0

What causes this error?

  1. after installing the plugin, using the following: ‘yarn add cypress-social-logins’

  2. and invoking the cypress test runner: ‘CYPRESS_BASE_URL=“https://accounts.google.com” yarn cypress’

  3. I’m getting the following error; Error: module not found: “ws” from file … /node_modules/puppeteer/lib/WebSocketTransport.js

  4. example code is:

module.exports = (on, config) => {
  on('task', {
    GoogleSocialLogin: GoogleSocialLogin
  })
}

describe('Login', () => {
  it('Login through Google', () => {
    const username = ('XYZ1234');
    const password = ('XYZ1234');
    const loginUrl = ('https://google.accounts.com/ServiceLogin')
    const cookieName = ('cookieName')

    const socialLoginOptions = {
      username,
      password,
      loginUrl,
      headless: false,
      logs: true,
      loginSelector: 'a[href="/auth/auth0/google-oauth2"]',
      postLoginSelector: '.account-panel'
    }

    return cy.task('GoogleSocialLogin', socialLoginOptions).then(({cookies}) => {
      cy.clearCookies()

      const cookie = cookies.filter(cookie => cookie.name === cookieName).pop()
      if (cookie) {
        cy.setCookie(cookie.name, cookie.value, {
          domain: cookie.domain,
          expiry: cookie.expires,
          httpOnly: cookie.httpOnly,
          path: cookie.path,
          secure: cookie.secure
        })

        Cypress.Cookies.defaults({
          whitelist: cookieName
        })
      }
    })
  })
})




About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 23 (13 by maintainers)

Most upvoted comments

No worries. This is what we have on the Troubleshooting section already so I hope it will be helpful for others in the future: image

@lirantal problem in chair , not in computer.

I have been spending all week in the /support/index.js and I blindly added it there over the /plugins/index.js

Apologies for my stupidity on this one. I need more coffee

I also ran into this issue.

The problem was I was requiring GoogleSocialLogin in my spec file in addition to requiring it in cypress/plugins/index.js.

Removing it from my spec file resolved the issue.

Sure. so it should be something as follows:

cypress/plugins/index.js should look as:

const { GoogleSocialLogin } = require("cypress-social-logins").plugins;

module.exports = (on, config) => {
  on("task", {
    GoogleSocialLogin: GoogleSocialLogin
  });
};

cypress.json along the lines of:

{
  "baseUrl": "https://app.snyk.io",
  "env": {
    "username": "XYZ@gmail.com",
    "password": "XYZ",
    "cookieName": "cookieID",
    "googleSocialLoginUsername": "XYZ@gmail.com",
    "googleSocialLoginPassword": "XYZ",
    "loginUrl": "https://myapp/login",
    "homepage": "https://somehomepage"
  }
}

And finally using it in a test is something along the lines of:

export const login = ({
  username = Cypress.env("googleSocialLoginUsername"),
  password = Cypress.env("googleSocialLoginPassword")
} = {}) => {
  describe("Login", () => {
    it("Login through Google", () => {
      const cookieName = Cypress.env("cookieName");
      const socialLoginOptions = {
        username,
        password,
        loginUrl: Cypress.env("loginUrl"),
        headless: false,
        logs: false,
        loginSelector: 'a[href="/auth/auth0/google-oauth2"]',
        postLoginSelector: ".account-panel"
      };

      return cy
        .task("GoogleSocialLogin", socialLoginOptions)
        .then(({ cookies }) => {
          cy.clearCookies();

          const cookie = cookies
            .filter(cookie => cookie.name === cookieName)
            .pop();
          if (cookie) {
            cy.setCookie(cookie.name, cookie.value, {
              domain: cookie.domain,
              expiry: cookie.expires,
              httpOnly: cookie.httpOnly,
              path: cookie.path,
              secure: cookie.secure
            });

            Cypress.Cookies.defaults({
              whitelist: cookieName
            });
          }
        });
    });
  });
};