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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(autoLogin): improve the check method #3935

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
9 checks passed
@kobenguyent kobenguyent deleted the 3759-feature-request-allow-check-in-autologin-plugin-to-access-session-data branch October 28, 2023 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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