You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Question] How to launch an error in autoLogin custom step #2600
I've implemented an autoLogin based on REST calls, to optimize the time in login and check processes, the problem is that when the token is invalid I don't know how to mark the check process as invalid so the workflow continues with login stage, if I throw an Error() the entire autoLogin process is halt due to an unexpected error. All the examples I saw use the existing API based on user interface where the user fill-in the credentials in a form and so on, but I didn't find anything using REST helper.
As (ugly) workaround I've got the following code in autoLogin.check implementation:
check: async(I)=>{console.log('admin.check');consttoken=codeceptjs.store['admin_session'];constisValid=awaitI.validateToken(token);if(!isValid){I.see("NOTHING TO SEE HERE, so It'll fail");}},
By the way, I launched the same question in StackOverflow with a bounty, but without luck by the moment.
Hi @brunoklein , assert.fail() doesn't work, the result is similar to throw Error()in this case.
(node:2245) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: Failed
at Object.validateToken (/home/rob/git/QO/HEMERA/hemera-tests-e2e/hemera/api/session.js:59:10)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async Object.check (/home/rob/git/QO/HEMERA/hemera-tests-e2e/codecept.conf.js:84:29)
at async loginFunction (/home/rob/git/QO/HEMERA/hemera-tests-e2e/node_modules/codeceptjs/lib/plugin/autoLogin.js:271:7)
(node:2245) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2245) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
In other words, the whole Scenario is marked as failure, because this is like an unexpected error, the autoLogin plugin has a workflow, explained in https://codecept.io/plugins/#autologin, but the workflow doesn't continue when check stage fails, the expected result is to continue with the login stage where I get a new token because the existing one is invalid.
Activity
brunoklein commentedon Sep 28, 2020
Hey Roberto! How about use the assert.fail method? It will fail your entire Scenario and you can customize the message!
Check method:
rsc1975 commentedon Sep 28, 2020
Hi @brunoklein ,
assert.fail()doesn't work, the result is similar tothrow Error()in this case.In other words, the whole Scenario is marked as failure, because this is like an unexpected error, the autoLogin plugin has a workflow, explained in https://codecept.io/plugins/#autologin, but the workflow doesn't continue when
checkstage fails, the expected result is to continue with theloginstage where I get a new token because the existing one is invalid.brunoklein commentedon Sep 28, 2020
Which node and codeceptjs version are you using?
rsc1975 commentedon Sep 28, 2020