autoLogin - general

I try to use the autoLogin plugin inside my test but I only get
Could not load plugin autoLogin from module ‘:/plugin/autoLogin’: Cannot convert undefined or null to object

Do I have to download the or install the plugin?

did you follow this tutorial here: https://codecept.io/plugins#autologin or check if you use the proper codeceptjs version?

I have installed codeceptjs on Monday, so I assume that the the version is ok. I used the sample page. But as you see the message looks like that something is missing. I am lost in this case, because if something is missed it have to be installed. But I cannot read anything about installing a plugin.

please provide your debug log, it’s better to sort things out!

The only output I can provide is:

Could not load plugin autoLogin from module ‘./plugin/autoLogin’:
Cannot convert undefined or null to object

Error:
at createPlugins (/usr/lib/node_modules/codeceptjs-webdriverio/node_modules/codeceptjs/lib/container.js:228:13)
at Function.create (/usr/lib/node_modules/codeceptjs-webdriverio/node_modules/codeceptjs/lib/container.js:36:25)
at Codecept.init (/usr/lib/node_modules/codeceptjs-webdriverio/node_modules/codeceptjs/lib/codecept.js:55:15)
at Command.module.exports (/usr/lib/node_modules/codeceptjs-webdriverio/node_modules/codeceptjs/lib/command/run.js:33:14)
at Command.listener (/usr/lib/node_modules/codeceptjs-webdriverio/node_modules/commander/index.js:315:8)
at Command.emit (events.js:196:13)
at Command.parseArgs (/usr/lib/node_modules/codeceptjs-webdriverio/node_modules/commander/index.js:651:12)
at Command.parse (/usr/lib/node_modules/codeceptjs-webdriverio/node_modules/commander/index.js:474:21)
at Object. (/usr/lib/node_modules/codeceptjs-webdriverio/node_modules/codeceptjs/bin/codecept.js:144:9)
at Module._compile (internal/modules/cjs/loader.js:759:30)

Is this what you need?

maybe there is a little full login test sample available to show how to right configure the test and the steps?

I am getting the same error
Could not load plugin autoLogin from module ‘./plugin/autoLogin’:
Cannot convert undefined or null to object

codeceptjs version 2.2.0

@vialy @peterngtr @Ognif

Probably your option saveToFile: true in autoLogin config,
And this way plugin saves user_session.json file with an undefined value, and that’s why framework can’t start.
I don’t know why, but the plugin saves cookies to this file right after the browser starts, and for this moment there aren’t any cookies.
I’m trying to use it with the puppeteer. And don’t know how to fix it. Probably the best solution to write login as step object by yourself for now

1 Like

Lol, your should just remove fetch and restore options from config and everything runs perfect

@Ognif Hi, welcome to the community!

Here’s an example of how I use the autoLogin plugin in my project without errors. I had the same problem as you.

        autoLogin: {
            enabled: true,
            saveToFile: false, // set this to false if you don't need to pass cookies to other sessions
            inject: 'loginAs', // use `loginAs` instead of login
            users: {
                Admin: {
                    login: (I) => {
                        I.amOnPage(`/`);
                        I.fillField('some-field-locator', 'your values here');
                        I.fillField('some-password-field', 'your values here');
                        I.click('button-locator-here');
                    },
                    check: (I) => {
                        I.seeInCurrentUrl('/admin/');
                    },
                    fetch: () => {}, // empty function
                    restore: () => {}, // empty funciton
                },
                UserTypeA: {
                    login: (I) => {
                        I.amOnPage(`/`);
                        I.fillField('some-field-locator', 'your values here');
                        I.fillField('some-password-field', 'your values here');
                        I.click('button-locator-here');
                    },
                    check: (I) => {
                        I.seeInCurrentUrl('/user-profile');
                    },
                    fetch: () => {}, // empty function
                    restore: () => {}, // empty funciton
                },
                UserTypeB: {
                    login: (I) => {
                        I.amOnPage(`/`);
                        I.fillField('some-field-locator', 'your values here');
                        I.fillField('some-password-field', 'your values here');
                        I.click('button-locator-here');
                    },
                    check: (I) => {
                        I.seeInCurrentUrl('/myAccount');
                    },
                    fetch: () => {}, // empty function
                    restore: () => {}, // empty funciton
                },
            },
        },

        // in your test file you use your plugin like some
        loginAs('Admin');
        loginAs('UserTypeA');
        // if you have async code in your login steps, make sure you use `async/await` correctly, let me know if you need an example