From 7a0f7ffa3b08d2cfa512fc2448c8dae2a944af4e Mon Sep 17 00:00:00 2001 From: Ando NARY <36852616+andonary@users.noreply.github.com> Date: Sat, 28 Oct 2023 20:23:58 +0200 Subject: [PATCH] fix: autologin with empty fetch (#3947) --- docs/webdriver.md | 2 +- lib/plugin/autoLogin.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/webdriver.md b/docs/webdriver.md index 4a114c0cd..3f69191b1 100644 --- a/docs/webdriver.md +++ b/docs/webdriver.md @@ -447,7 +447,7 @@ To share the same user session across different tests CodeceptJS provides [autoL This plugin requires some configuration but is very simple in use: ```js -Scenario('do something with logged in user', ({ I, login) }) => { +Scenario('do something with logged in user', ({ I, login }) => { login('user'); I.see('Dashboard','h1'); }); diff --git a/lib/plugin/autoLogin.js b/lib/plugin/autoLogin.js index f4dc9a5db..7930a0e59 100644 --- a/lib/plugin/autoLogin.js +++ b/lib/plugin/autoLogin.js @@ -9,6 +9,7 @@ const isAsyncFunction = require('../utils').isAsyncFunction; const defaultUser = { fetch: I => I.grabCookie(), + check: () => {}, restore: (I, cookies) => { I.amOnPage('/'); // open a page I.setCookie(cookies); @@ -283,7 +284,12 @@ module.exports = function (config) { } else { userSession.login(I); } + const cookies = await userSession.fetch(I); + if (!cookies) { + debug('Cannot save user session with empty cookies from auto login\'s fetch method'); + return; + } if (config.saveToFile) { debug(`Saved user session into file for ${name}`); fs.writeFileSync(path.join(global.output_dir, `${name}_session.json`), JSON.stringify(cookies));