Skip to content

Commit 7a0f7ff

Browse files
authored
fix: autologin with empty fetch (#3947)
1 parent f78c027 commit 7a0f7ff

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

docs/webdriver.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ To share the same user session across different tests CodeceptJS provides [autoL
447447
This plugin requires some configuration but is very simple in use:
448448
449449
```js
450-
Scenario('do something with logged in user', ({ I, login) }) => {
450+
Scenario('do something with logged in user', ({ I, login }) => {
451451
login('user');
452452
I.see('Dashboard','h1');
453453
});

lib/plugin/autoLogin.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const isAsyncFunction = require('../utils').isAsyncFunction;
99

1010
const defaultUser = {
1111
fetch: I => I.grabCookie(),
12+
check: () => {},
1213
restore: (I, cookies) => {
1314
I.amOnPage('/'); // open a page
1415
I.setCookie(cookies);
@@ -283,7 +284,12 @@ module.exports = function (config) {
283284
} else {
284285
userSession.login(I);
285286
}
287+
286288
const cookies = await userSession.fetch(I);
289+
if (!cookies) {
290+
debug('Cannot save user session with empty cookies from auto login\'s fetch method');
291+
return;
292+
}
287293
if (config.saveToFile) {
288294
debug(`Saved user session into file for ${name}`);
289295
fs.writeFileSync(path.join(global.output_dir, `${name}_session.json`), JSON.stringify(cookies));

0 commit comments

Comments
 (0)