Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to remain signed in throughout a single test #108

Open
galiavasylieva opened this issue Nov 24, 2021 · 0 comments
Open

Not able to remain signed in throughout a single test #108

galiavasylieva opened this issue Nov 24, 2021 · 0 comments

Comments

@galiavasylieva
Copy link

I am using cypress-social-logins plugin to signin to the web application via Google.

I have:

  1. custom command googlesignin in support/commands.js that has following:
Cypress.Commands.add('googlesignin', (usrn, pwd, verifSelector) => {
  const username = usrn;
  const password = pwd;
  const loginUrl = 'url_to_the_page_that_has_signup_with_google_button';
  const cookieName = 'cookie_name';
  const postLoginSelector = verifSelector;
  const socialLoginOptions = {
    username: username,
    password: password,
    loginUrl: loginUrl,
    headless: true,
    logs: true,
    loginSelector: 'a[href="/api/auth/google"]',
    postLoginSelector: postLoginSelector,
  };

  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,
          session: cookie.session,
          sameSite: cookie.sameSite,
          size: cookie.size,
        });
        Cypress.Cookies.defaults({
          preserve: cookieName,
        });
      }
    });
});
  1. plugins/index.js file with:
const { GoogleSocialLogin } = require('cypress-social-logins').plugins;
module.exports = async (on, config) => {
  on('task', {
    GoogleSocialLogin: GoogleSocialLogin
  });
  return config;
};
  1. My test:
  describe('SocialSignin', () => {
  beforeEach(() => {
    cy.visit('/signin');
  });
    it('user expects to be able to signin with the Gmail account', () => {
      cy.googlesignin(
        Cypress.env('registeredGoogleUsername'),
        Cypress.env('registeredGooglePassword'),
        'a',
      );
      cy.visit("/signup")
      cy.url().should('contain', '/home');
    });

ACTUAL BEHAVIOUR:

The test is passing.
When I set headless: false in socialLoginOptions - I can see puppeteer going through all the process, logging in with google.
Cookies are being set as well.

BUT When it gets to the cy.visit("/signup") step <---- I expect to be redirected to /home (that is by our app design and working as expected manually), but instead I end up on /signup page UNAUTHENTICATED.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant