codeceptjs / CodeceptJS

Supercharged End 2 End Testing Framework for NodeJS
http://codecept.io
MIT License
4.11k stars 725 forks source link

done called multiple times when interacting with button in iFrame that causes iFrame to close #3347

Closed costag1982 closed 2 years ago

costag1982 commented 2 years ago

What are you trying to achieve?

I am trying to get into the iFrame to click on the accept cookie button

image

What do you get instead?

I get an error stating done called multiple times

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

1) housePricesSearch
       Search for a particular property in the house prices search and confirm that it appears as the first result:
     Uncaught frame.frameElement: Frame has been detached.
      at /Users/costagiannakopoulos/Workspace/TechTests/Costa-Giannakopoulos/node_modules/codeceptjs/lib/helper/Playwright.js:2756:46

  Scenario Steps:
  - I.click("#save") at ./steps/steps_file.js:31:14
  - I.wait(10) at ./steps/steps_file.js:30:14
  - I.waitForElement("#gdpr-consent-notice") at Actor.amOnTheHomepage (./steps/steps_file.js:28:12)
  - I.amOnPage("/") at Actor.amOnTheHomepage (./steps/steps_file.js:27:12)

  FAIL  | 0 passed, 1 failed   // 19s
Run with --verbose flag to see complete NodeJS stacktrace
/Users/costagiannakopoulos/Workspace/TechTests/Costa-Giannakopoulos/node_modules/mocha/lib/runner.js:906
    throw err;
    ^

Error: done() called multiple times in test <housePricesSearch: Search for a particular property in the house prices search and confirm that it appears as the first result> of file /Users/costagiannakopoulos/Workspace/TechTests/Costa-Giannakopoulos/test/housePricesSearch_test.js; in addition, done() received error: page.$$: Target page, context or browser has been closed
    at Playwright.findElements (/Users/costagiannakopoulos/Workspace/TechTests/Costa-Giannakopoulos/node_modules/codeceptjs/lib/helper/Playwright.js:2482:18)
    at Playwright.findClickable (/Users/costagiannakopoulos/Workspace/TechTests/Costa-Giannakopoulos/node_modules/codeceptjs/lib/helper/Playwright.js:2537:28)
    at Playwright.proceedClick (/Users/costagiannakopoulos/Workspace/TechTests/Costa-Giannakopoulos/node_modules/codeceptjs/lib/helper/Playwright.js:2505:35) {
  name: 'Error'
}
    at createMultipleDoneError (/Users/costagiannakopoulos/Workspace/TechTests/Costa-Giannakopoulos/node_modules/mocha/lib/errors.js:294:13)
    at multiple (/Users/costagiannakopoulos/Workspace/TechTests/Costa-Giannakopoulos/node_modules/mocha/lib/runnable.js:282:24)
    at done (/Users/costagiannakopoulos/Workspace/TechTests/Costa-Giannakopoulos/node_modules/mocha/lib/runnable.js:293:14)
    at /Users/costagiannakopoulos/Workspace/TechTests/Costa-Giannakopoulos/node_modules/mocha/lib/runnable.js:388:16
    at /Users/costagiannakopoulos/Workspace/TechTests/Costa-Giannakopoulos/node_modules/codeceptjs/lib/scenario.js:52:26 {
  code: 'ERR_MOCHA_MULTIPLE_DONE',
  valueType: 'object',
  value: page.$$: Target page, context or browser has been closed
      at Playwright.findElements (/Users/costagiannakopoulos/Workspace/TechTests/Costa-Giannakopoulos/node_modules/codeceptjs/lib/helper/Playwright.js:2482:18)
      at Playwright.findClickable (/Users/costagiannakopoulos/Workspace/TechTests/Costa-Giannakopoulos/node_modules/codeceptjs/lib/helper/Playwright.js:2537:28)
      at Playwright.proceedClick (/Users/costagiannakopoulos/Workspace/TechTests/Costa-Giannakopoulos/node_modules/codeceptjs/lib/helper/Playwright.js:2505:35) {
    name: 'Error'
  }
}

Provide test source code if related

amOnTheHomepage() {
      this.amOnPage('/');
      this.waitForElement("#gdpr-consent-notice")
      within({frame: "#gdpr-consent-notice"}, () => {
        this.click('#save');
      });
    },

Details

const { setHeadlessWhen, setCommonPlugins } = require('@codeceptjs/configure');

// turn on headless mode when running with HEADLESS=true environment variable
// export HEADLESS=true && npx codeceptjs run
setHeadlessWhen(process.env.HEADLESS);

// enable all common plugins https://github.com/codeceptjs/configure#setcommonplugins
setCommonPlugins();

exports.config = {
  tests: './test/*_test.js',
  output: './output',
  helpers: {
    Playwright: {
      url: 'https://www.zoopla.co.uk',
      show: true,
      browser: 'webkit',
      video: true,
      waitForNavigation: "networkidle",
      waitForAction: 200,
      fullPageScreenshots: true,
      locale: "en-GB",
    }
  },
  include: {
    I: "./steps/steps_file.js", // if i had more time i would create more steps file to improve readability
  },
  bootstrap: null,
  mocha: { bail: true },
  name: 'Costa-Giannakopoulos',
  plugins: {
    subtitles: {
      enabled: true,
    },
    screenshotOnFail: {
      enabled: true,
    },
    customLocator: {
      enabled: true,
      attribute: "data-testid",
    },
    autoDelay: {
      enabled: true,
    },
    pauseOnFail: {
      enabled: true,
    },
    tryTo: {
      enabled: true,
    },
    retryTo: {
      enabled: true,
    },
  }
}
kobenguyent commented 2 years ago

It's supposed to be the node version that causes this error. Did you happen to try other node version? From my case, I'm using node 12 and that error eliminated.

costag1982 commented 2 years ago

Ah @PeterNgTr I will try that, im currently using node 16, thanks for the tip. Is this something that will be fixed on later node versions?

costag1982 commented 2 years ago

Yes it works on node 14, thanks for this.

costag1982 commented 2 years ago

its still not perfect on node 14 and 12

(node:25336) UnhandledPromiseRejectionWarning: frame.frameElement: Frame has been detached. at /Users/costagiannakopoulos/Workspace/TechTests/Costa-Giannakopoulos/node_modules/codeceptjs/lib/helper/Playwright.js:2756:46 (node:25336) 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: 2) (node:25336) [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. (node:25336) UnhandledPromiseRejectionWarning: frame.frameElement: Frame has been detached. at /Users/costagiannakopoulos/Workspace/TechTests/Costa-Giannakopoulos/node_modules/codeceptjs/lib/helper/Playwright.js:2756:46 (node:25336) 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: 4) I click "Sign in" ✖ FAILED in 3741ms

kobenguyent commented 2 years ago

I guess that's another story cause you don't encounter done() called multiple times with node14 right 😁

costag1982 commented 2 years ago

@PeterNgTr yes thats true haha. The error in node 14 and 12 is intermittent where as the node 16 is every time.

looks like there are 2 issues on this ticket now :)

costag1982 commented 2 years ago

looks like the latter issue is already logged - https://github.com/codeceptjs/CodeceptJS/issues/3313

costag1982 commented 2 years ago

How come this issue is closed @PeterNgTr? Does it not need fixing for node 16 users?

kalyan0922 commented 2 years ago

@costag1982 try this work around

this.usePlaywrightTo(“within frame”,async({page}) => { const frame = await page.frameLocator("#gdpr-consent-notice"); frame.locator("css=#save").click(); }) // continue on main page