Skip to content

feat(autoLogin): improve the check method #3935

New issue

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

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

Already on GitHub? # to your account

Conversation

kobenguyent
Copy link
Collaborator

@kobenguyent kobenguyent commented Oct 19, 2023

Motivation/Description of the PR

Instead of asserting on page elements for the current user in check, you can use the session you saved in fetch

autoLogin: {
  enabled: true,
  saveToFile: true,
  inject: 'login',
  users: {
    admin: {
      login: async (I) => {  // If you use async function in the autoLogin plugin
         const phrase = await I.grabTextFrom('#phrase')
         I.fillField('username', 'admin'),
         I.fillField('password', 'password')
         I.fillField('phrase', phrase)
      },
      check: (I, session) => {
         // Throwing an error in `check` will make CodeceptJS perform the login step for the user
         if (session.profile.email !== the.email.you.expect@some-mail.com) {
              throw new Error ('Wrong user signed in');
        }
      },
    }
  }
}
Scenario('login', async ( {I, login} ) => {
  await login('admin') // you should use `await`
})

Applicable plugins:

  • autoLogin

Type of change

  • 🚀 New functionality

Checklist:

  • Tests have been added
  • Documentation has been added (Run npm run docs)
  • Lint checking (Run npm run lint)
  • Local tests are passed (Run npm test)

@kobenguyent kobenguyent changed the title improve the check method feat(autoLogin): improve the check method Oct 19, 2023
@Arhell Arhell requested a review from DavertMik October 22, 2023 06:33
@kobenguyent kobenguyent merged commit dc036b8 into 3.x Oct 28, 2023
@kobenguyent kobenguyent deleted the 3759-feature-request-allow-check-in-autologin-plugin-to-access-session-data branch October 28, 2023 07:14
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Allow check in autoLogin plugin to access session data
2 participants