You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1.`restore` method is executed. It should open a page and set credentials.
92
-
2.`check` method is executed. It should reload a page (so cookies are applied) and check that this page belongs to loggedin user.
92
+
2.`check` method is executed. It should reload a page (so cookies are applied) and check that this page belongs to logged-in user. When you pass the second args `session`, you could perform the validation using passed session.
93
93
3. If `restore` and `check` were not successful, `login` is executed
94
94
4.`login` should fill in login form
95
95
5. After successful login, `fetch` is executed to save cookies into memory or file.
Copy file name to clipboardExpand all lines: lib/plugin/autoLogin.js
+35-3Lines changed: 35 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,7 @@ const defaultConfig = {
61
61
* #### How It Works
62
62
*
63
63
* 1. `restore` method is executed. It should open a page and set credentials.
64
-
* 2. `check` method is executed. It should reload a page (so cookies are applied) and check that this page belongs to loggedin user.
64
+
* 2. `check` method is executed. It should reload a page (so cookies are applied) and check that this page belongs to logged-in user. When you pass the second args `session`, you could perform the validation using passed session.
65
65
* 3. If `restore` and `check` were not successful, `login` is executed
66
66
* 4. `login` should fill in login form
67
67
* 5. After successful login, `fetch` is executed to save cookies into memory or file.
@@ -212,6 +212,38 @@ const defaultConfig = {
212
212
* })
213
213
* ```
214
214
*
215
+
* #### Tips: Using session to validate user
216
+
*
217
+
* Instead of asserting on page elements for the current user in `check`, you can use the `session` you saved in `fetch`
218
+
*
219
+
* ```js
220
+
* autoLogin: {
221
+
* enabled: true,
222
+
* saveToFile: true,
223
+
* inject: 'login',
224
+
* users: {
225
+
* admin: {
226
+
* login: async (I) => { // If you use async function in the autoLogin plugin
227
+
* const phrase = await I.grabTextFrom('#phrase')
228
+
* I.fillField('username', 'admin'),
229
+
* I.fillField('password', 'password')
230
+
* I.fillField('phrase', phrase)
231
+
* },
232
+
* check: (I, session) => {
233
+
* // Throwing an error in `check` will make CodeceptJS perform the login step for the user
234
+
* if (session.profile.email !== the.email.you.expect@some-mail.com) {
235
+
* throw new Error ('Wrong user signed in');
236
+
* }
237
+
* },
238
+
* }
239
+
* }
240
+
* }
241
+
* ```
242
+
*
243
+
* ```js
244
+
* Scenario('login', async ( {I, login} ) => {
245
+
* await login('admin') // you should use `await`
246
+
* })
215
247
*
216
248
*
217
249
*/
@@ -264,10 +296,10 @@ module.exports = function (config) {
264
296
recorder.session.start('check login');
265
297
if(shouldAwait){
266
298
awaituserSession.restore(I,cookies);
267
-
awaituserSession.check(I);
299
+
awaituserSession.check(I,cookies);
268
300
}else{
269
301
userSession.restore(I,cookies);
270
-
userSession.check(I);
302
+
userSession.check(I,cookies);
271
303
}
272
304
recorder.session.catch((err)=>{
273
305
debug(`Failed auto login for ${name} due to ${err}`);
0 commit comments