Skip to content

Commit

Permalink
fix: autologin with empty fetch (#3947)
Browse files Browse the repository at this point in the history
  • Loading branch information
andonary authored Oct 28, 2023
1 parent f78c027 commit 7a0f7ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/webdriver.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down
6 changes: 6 additions & 0 deletions lib/plugin/autoLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 7a0f7ff

Please sign in to comment.