How to use the autoLogin() plugin with TypeScript testing
See original GitHub issueWhat are you trying to achieve?
I’m trying to use the autoLogin
plugin within a TypeScript test suite. I copied the examples from the documentation, but it doesn’t seem to be working. Perhaps some TS incompatibility?
What do you get instead?
The testing fails immediately, because function login()
is undefined.
Provide console output if related. Use
--verbose
mode for more details.
TSError: ⨯ Unable to compile TypeScript:oad:flatten Completed in 3ms
../../../../../../test-project/tests/e2e/tests/configuration/configuration_test.ts:6:2 - error TS2349: This expression is not callable.
Type 'SupportObject' has no call signatures.
6 login('user'); // login using user session
~~~~~
at createTSError (test-project\tests\e2e\node_modules\ts-node\src\index.ts:750:12)
at reportTSError (test-project\tests\e2e\node_modules\ts-node\src\index.ts:754:19)
at getOutput (test-project\tests\e2e\node_modules\ts-node\src\index.ts:941:36)
at Object.compile (test-project\tests\e2e\node_modules\ts-node\src\index.ts:1243:30)
at Module.m._compile (test-project\tests\e2e\node_modules\ts-node\src\index.ts:1370:30)
at Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Object.require.extensions.<computed> [as .ts] (test-project\tests\e2e\node_modules\ts-node\src\index.ts:1374:12)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
Provide test source code if related
// Copied from https://codecept.io/plugins/#autologin
Before(login => {
login('admin'); // login using user session
});
Details
- CodeceptJS version: 3.1.3
- NodeJS Version: 7.19.1
- Operating System: Windows 10 or Ubuntu Linux
- Configuration file:
require('ts-node/register');
const { setHeadlessWhen } = require('@codeceptjs/configure');
const { bootstrap } = require('./presettings.ts');
// turn on headless mode when running with HEADLESS=true environment variable
// HEADLESS=true npx codecept run
setHeadlessWhen(process.env.HEADLESS);
exports.config = {
name: 'E2E Testing',
tests: [
'./tests/configuration/**_test.ts',
],
output: './output',
helpers: {
Playwright: {
url: 'https://test-site.local/',
show: true,
browser: 'chromium',
// Keep cookies for all tests
keepCookies: true,
},
ChaiWrapper : {
"require": "codeceptjs-chai"
}
},
bootstrap: null,
mocha: {},
plugins: {
allure: {
},
autoLogin: {
enabled: true,
inject: 'login',
users: {
admin: {
login: (I) => {
I.amOnPage('/login.php');
I.fillField('log', 'test_admin_user');
I.fillField('pwd', 'test_admin_password');
I.click('Submit');
},
check: (I) => {
I.amOnPage('/dashboard');
I.see('Dashboard');
},
fetch: () => {
// Empty function
},
restore: () => {
// Empty function
},
}
}
},
pauseOnFail: {
},
retryFailedStep: {
enabled: true
},
tryTo: {
enabled: true
},
screenshotOnFail: {
enabled: true
}
},
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:15
Top Results From Across the Web
How to use the autoLogin plugin - CodeceptJS Community
I am trying to use the second approach by checking if a UI-element exists, and the test passes even thought I it shouldn't...
Read more >Plugins - CodeceptJS
autoLogin. Logs user in for the first test and reuses session for next tests. Works by saving cookies into memory or file. If...
Read more >Manage error in custom step for autologin in CodeceptJS
I'm using autoLogin plugin in CodeceptJS project with Puppeteer as testing lib. This is my first project with CodeceptJS, the autoLogin ...
Read more >Testing Your App | Cypress Documentation
In fact, after you start using Cypress for awhile, we believe that you may find ... This will automatically prefix cy.visit() and cy.request()...
Read more >CodeceptJS Skeleton - Medium
The test is written as a linear scenario of a user's action on a site. Each test is described inside ... Now also...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Did you rebuilt your definitions? You should now have an entry like this in your
steps.d.ts
file:I had to “manually” add this entry
login: (role: string) => {};
into thesteps.d.ts
file since it wasn’t autogenerated by thenpx codeceptjs def
command which also means you’ll need to remember to do again every time you rerun your definitions. Another solution would be to get it from the container usingconst login = codeceptjs.container.support('login');
which doesn’t depend on remembering to add it to the definitions file.