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

Change ssd to lsd in README example #45

Merged
merged 2 commits into from
Jul 2, 2020
Merged

Conversation

wadehammes
Copy link
Contributor

Description

Update README to fix miscalled ssd to lsd.

  • [ x] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

@wadehammes
Copy link
Contributor Author

@lirantal I think this is why I wasn't getting my token from localStorage in #36, the example in the README had a typo for the lsd portion.

@wadehammes
Copy link
Contributor Author

wadehammes commented Jul 2, 2020

@lirantal localStorage isn't persisting between tests using this approach, however utilizing the Cypress localStorage plugin (https://www.npmjs.com/package/cypress-localstorage-commands) works wonderfully:

import 'cypress-localstorage-commands';

before(() => {
  describe('SSO Login', () => {
    const username = Cypress.env('googleUser');
    const password = Cypress.env('googlePass');
    const loginUrl = Cypress.env('loginUrl');
    const cookieName = Cypress.env('cookie') // "jwt";
    const socialLoginOptions = {
      username,
      password,
      loginUrl,
      headless: true,
      logs: false,
      loginSelector: '.abcRioButton',
      postLoginSelector: '#searchWrapper',
      isPopup: true,
      popupDelay: 1000,
      args: ['--no-sandbox', '--disable-setuid-sandbox'],
    };

    cy.clearLocalStorageSnapshot();

    return cy.task('GoogleSocialLogin', socialLoginOptions).then(({lsd}) => {
      const hasJwt = Object.keys(lsd)
        .filter((item) => item === cookieName)
        .pop();

      if (hasJwt) {
        cy.window().then(() => {
          Object.keys(lsd).forEach((key) => {
            cy.setLocalStorage(key, lsd[key]);
          });
        });

        cy.saveLocalStorage();
      }
    });
  });
});

// Check for initial results on every test
beforeEach(() => {
  // restores localstorage from initial login
  cy.restoreLocalStorage();

  cy.server();
  cy.route('GET', 'search/*').as('getInitialResults');
  cy.visit('/');

  cy.wait('@getInitialResults').then((response) => {
    assert.isArray(response.response.body.results);
    assert.isNotNull(response.response.body.results);
  });
});

// Save localStorage after all tests
afterEach(() => {
  cy.saveLocalStorage();
});

Want me to add an addendum to the README with this plugin information and how to use in an example (I can clean up the above to remove unnecessary lines)?

@@ -63,7 +63,7 @@ return cy.task('GoogleSocialLogin', socialLoginOptions).then(({cookies,lsd,ssd})

cy.window().then(window => {
Object.keys(ssd).forEach(key => window.sessionStorage.setItem(key, ssd[key]));
Object.keys(lsd).forEach(key => window.sessionStorage.setItem(key, ssd[key]));
Object.keys(lsd).forEach(key => window.localStorage.setItem(key, lsd[key]));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wow, great catch!
as my friend @shaninja says: 🦅👁 ;-)

@lirantal
Copy link
Owner

lirantal commented Jul 2, 2020

@wadehammes as for the comment on #45 (comment) - sure I'd love it if you wanted to send in another PR to update the README with that doc entry, thank you for proposing! 🤗❤️

@lirantal lirantal merged commit 528fca6 into lirantal:master Jul 2, 2020
@lirantal
Copy link
Owner

lirantal commented Jul 2, 2020

🎉 This PR is included in version 1.4.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

None yet

2 participants