CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

The check() in autologin plugin is not invoked

Open learningandworking opened this issue 4 years ago • 5 comments

What are you trying to achieve?

I am trying to assert an element by check() of auto-login plugin e.g. I.say("Hello from check()"); << is not printed out.

What do you get instead?

The check() is not invoked: the commands inside check() has not invoked.

Provide console output if related. Use --verbose mode for more details.

Authentication --
    [1] Starting recording promises
    Emitted | suite.before ([object Object])
  log me in
    Emitted | test.before ([object Object])
    Emitted | test.start ([object Object])
    Error processing test.start event:
    TypeError: helpers[key][hook] is not a function
    at /codecept-ign/node_modules/codeceptjs/lib/listener/helpers.js:16:25
    at Array.forEach (<anonymous>)
    at runHelpersHook (/codecept-ign/node_modules/codeceptjs/lib/listener/helpers.js:15:26)
    at EventEmitter.<anonymous> (/codecept-ign/node_modules/codeceptjs/lib/listener/helpers.js:39:5)
    at EventEmitter.emit (events.js:214:15)
    at Object.emit (/codecept-ign/node_modules/codeceptjs/lib/event.js:51:28)
    at Context.test.fn (/codecept-ign/node_modules/codeceptjs/lib/scenario.js:77:13)
    at callFnAsync (/codecept-ign/node_modules/mocha/lib/runnable.js:415:21)
    at Test.Runnable.run (/codecept-ign/node_modules/mocha/lib/runnable.js:357:7)
    at Runner.runTest (/codecept-ign/node_modules/mocha/lib/runner.js:535:10)
    [1] Starting <check login> session
    Emitted | step.before (I am on page "/")
    Emitted | step.after (I am on page "/")
    Emitted | step.before (I set cookie [{"name":"_gid","value":"GA1.2.716511011.1573121252","domain":".ignitionadvice.com","path":"…
    Emitted | step.after (I set cookie [{"name":"_gid","value":"GA1.2.716511011.1573121252","domain":".ignitionadvice.com","path":"/…
    Emitted | step.before (I am on page "/")
    Emitted | step.after (I am on page "/")
    Emitted | step.before (I see "Admin")
    Emitted | step.after (I see "Admin")
    Emitted | step.start (I am on page "/")
    I am on page "/"
    [1] <check login> Error | Error: Protocol error (Page.navigate): Cannot navigate to invalid URL
    Emitted | step.failed (I am on page "/")
    Emitted | step.finish (I am on page "/")
    [1] <check login> Error | Error: Protocol error (Page.navigate): Cannot navigate to invalid URL
    Emitted | step.failed (I set cookie [{"name":"_gid","value":"GA1.2.716511011.1573121252","domain":".ignitionadvice.com","path":"…
    Emitted | step.finish (I set cookie [{"name":"_gid","value":"GA1.2.716511011.1573121252","domain":".ignitionadvice.com","path":"…
    [1] <check login> Error | Error: Protocol error (Page.navigate): Cannot navigate to invalid URL
    Emitted | step.failed (I am on page "/")
    Emitted | step.finish (I am on page "/")
    [1] <check login> Error | Error: Protocol error (Page.navigate): Cannot navigate to invalid URL
    Emitted | step.failed (I see "Admin")
    Emitted | step.finish (I see "Admin")
 › Failed auto login for adviser due to Error: Protocol error (Page.navigate): Cannot navigate to invalid URL
 › Logging in again
    [1] <check login> Starting <auto login> session
    Emitted | step.before (I am on page "https://{{url}}/login")
    Emitted | step.after (I am on page "https://{{url}}/login")
    Emitted | step.before (I wait for visible "[data-test="login-username"]", 3)
    Emitted | step.after (I wait for visible "[data-test="login-username"]", 3)
    Emitted | step.before (I fill field "[data-test="login-username"]", "adviser.account")
    Emitted | step.after (I fill field "[data-test="login-username"]", "adviser.account")
    Emitted | step.before (I fill field "[data-test="login-password"]", *****)
    Emitted | step.after (I fill field "[data-test="login-password"]", *****)
    Emitted | step.before (I click "button[data-test="login-button"]")
    Emitted | step.after (I click "button[data-test="login-button"]")
    Emitted | step.before (I grab cookie )
    Emitted | step.after (I grab cookie )
    Emitted | step.start (I am on page "https://{{url}}/login")
    I am on page "https://{{url}}/login"
    › [Url] https://{{url}}/login
    › [Browser:Error] Failed to load resource: the server responded with a status of 400 ()
    Emitted | step.passed (I am on page "https://{{url}}/login")
    Emitted | step.finish (I am on page "https://{{url}}/login")
    Emitted | step.start (I wait for visible "[data-test="login-username"]", 3)
    I wait for visible "[data-test="login-username"]", 3
    Emitted | step.passed (I wait for visible "[data-test="login-username"]", 3)
    Emitted | step.finish (I wait for visible "[data-test="login-username"]", 3)
    Emitted | step.start (I fill field "[data-test="login-username"]", "adviser.account")
    I fill field "[data-test="login-username"]", "adviser.account"
    Emitted | step.passed (I fill field "[data-test="login-username"]", "adviser.account")
    Emitted | step.finish (I fill field "[data-test="login-username"]", "adviser.account")
    Emitted | step.start (I fill field "[data-test="login-password"]", *****)
    I fill field "[data-test="login-password"]", *****
    Emitted | step.passed (I fill field "[data-test="login-password"]", *****)
    Emitted | step.finish (I fill field "[data-test="login-password"]", *****)
    Emitted | step.start (I click "button[data-test="login-button"]")
    I click "button[data-test="login-button"]"
    Emitted | step.passed (I click "button[data-test="login-button"]")
    Emitted | step.finish (I click "button[data-test="login-button"]")
    Emitted | step.start (I grab cookie )
    I grab cookie 
    Emitted | step.passed (I grab cookie )
    Emitted | step.finish (I grab cookie )
 › Saved user session into file for adviser
    [1] <auto login> Finalize <auto login> session
    [1] Finalize <check login> session
    Emitted | test.passed ([object Object])
    Emitted | test.finish ([object Object])
  ✔ OK in 10963ms

    Emitted | test.after ([object Object])
    Emitted | suite.after ([object Object])

  OK  | 1 passed   // 12s
    Emitted | global.result ([object Object])
    Emitted | global.after ([object Object])

Provide test source code if related

//const authen = require('../pages/Login.js/index.js');
const assert = require('assert');
const {I} = inject();

Feature('Authentication');

 
 // Alternatively log in for one scenario
 Scenario('log me in', (I, loginAs) => {
    loginAs('adviser');

 });


Details

  • CodeceptJS version:
"devDependencies": {
    "@codeceptjs/mailslurp-helper": "^1.0.2",
    "codeceptjs": "^2.3.5",
    "dotenv": "^8.2.0",
    "puppeteer": "^1.20.0"
  }
  • NodeJS Version: v12.10.0
  • Operating System: MAC OS
  • Library: Pupeteer
  • Configuration file:
const env = require('dotenv').config();
//const authen = require('./specs/helper/Authentication');
let URL = env.parsed.BASED_URL;
let adviser_usr = env.parsed.ADVISER_USERNAME;
let adviser_pwd = env.parsed.ADVISER_PWD;
const mailslurp_key = require('./credential').mailslurp.key


exports.config = {
  tests: './specs/**/*.spec.js',
  output: './output',
  helpers: {
    Puppeteer: {
      //url: URL,
      show: true,
      waitForNavigation: "networkidle0"
    },
    MailSlurp: {
      require: '@codeceptjs/mailslurp-helper',
      apiKey: mailslurp_key
    },
  },
  plugins: {
    autoLogin: {
      enabled: true,
      saveToFile: true,
      inject: 'loginAs',
      users: {
        adviser: {
          loginAs: (I) => I.loginTo(`${URL}/login`, adviser_usr, adviser_pwd),
          check: (I) => {
            I.amOnPage('/');
            I.say("Hello from check()");
      
          }
        }
      }
    },
  },
  include: {
    I: './steps_file.js'
  },
  bootstrap: null,
  mocha: {},
  name: 'codecept-ign'
}

learningandworking avatar Nov 07 '19 10:11 learningandworking

i had the same problem....

shaaimin avatar Nov 14 '19 01:11 shaaimin

Hi all Is it updated on this thread ?

learningandworking avatar Nov 29 '19 15:11 learningandworking

any news ?

spham avatar Mar 11 '20 08:03 spham

it's still there :(

Bakanych avatar Sep 28 '20 09:09 Bakanych

Same as #1591. See the answer there too: https://github.com/codeceptjs/CodeceptJS/issues/1591#issuecomment-480800333 You need to return some garbage value from fetch, e.g. just add fetch: () => "whatever" after check.

joshbax189 avatar Dec 22 '21 04:12 joshbax189

Closed for now! Feel free to reopen if you still encounter the issue with latest version and would be nice to provide a sample code to reproduce the issue.

kobenguyent avatar Dec 01 '23 16:12 kobenguyent