CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

Puppeteer always gives warnings that popups exist

Open adampbutler opened this issue 4 years ago • 0 comments

What are you trying to achieve?

Test with popups (eg. window.confirm) using unhandled-rejections=strict flag

What do you get instead?

Verbose output complaining about popups existing. Also in our application we use the unhandled-rejections=strict flag for node so the unhandled promises do not just cause output but also causes tests to fail.

Please see bare-bones sample project generated from codeceptjs init here: https://github.com/adampbutler/codecept-popup-issue

Setting restart: true on puppeteer works but makes the tests very slow. I believe the dialog event is not getting removed between tests and the clear method is not exposed so I believe we cannot remove ourselves.

> [email protected] test C:\work\codecept-issue\codecept-app
> codeceptjs run --steps

CodeceptJS v3.2.2
Using test root "C:\work\codecept-issue\codecept-app"

popup1 --
  test something1
    I am on page "https://adampbutler.github.io/codecept-popup-issue/test_page.html"
    I see "Click Me"
  √ OK in 468ms

popup2 --
  test something2
    I am on page "https://adampbutler.github.io/codecept-popup-issue/test_page.html"
    I click "Click Me"
Popup already exists and was not closed. Popups must always be closed by calling either I.acceptPopup() or I.cancelPopup()
(node:24484) UnhandledPromiseRejectionWarning: Error: Cannot accept dialog which is already handled!
    at assert (C:\work\codecept-issue\codecept-app\node_modules\puppeteer\lib\cjs\puppeteer\common\assert.js:26:15)
    at Dialog.accept (C:\work\codecept-issue\codecept-app\node_modules\puppeteer\lib\cjs\puppeteer\common\Dialog.js:79:32)
    at C:\work\codecept-issue\codecept-app\node_modules\codeceptjs\lib\helper\Puppeteer.js:483:25
(Use `node --trace-warnings ...` to show where the warning was created)
(node:24484) 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:24484) [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.
    I accept popup
    I see "Click Me"
  √ OK in 446ms

Provide test source code if related

// the failure does not happen if the popup is opened on the first feature
Feature('popup1');
Scenario('test something1', async ({ I }) => {
  await I.amOnPage('https://adampbutler.github.io/codecept-popup-issue/test_page.html');
  await I.see('Click Me');
});
Feature('popup2');
Scenario('test something2', async ({ I }) => {
  await I.amOnPage('https://adampbutler.github.io/codecept-popup-issue/test_page.html');
  await I.click('Click Me');
  await I.acceptPopup();
  await I.see('Click Me');
});

Details

  • CodeceptJS version: 3.2.2
  • NodeJS Version: 14.7.3
  • Operating System: Windows
  • puppeteer 13.0.1
  • Configuration file:
const { setHeadlessWhen } = require('@codeceptjs/configure');

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

exports.config = {
  tests: './*_test.js',
  output: './output',
  helpers: {
    Puppeteer: {
      url: 'https://adampbutler.github.io/codecept-popup-issue/test_page.html',
      show: true,
      restart: false,
      windowSize: '1200x900'
    }
  },
  include: {
    I: './steps_file.js'
  },
  bootstrap: null,
  mocha: {},
  name: 'codecept-app',
  plugins: {
    pauseOnFail: {},
    retryFailedStep: {
      enabled: true
    },
    tryTo: {
      enabled: true
    },
    screenshotOnFail: {
      enabled: true
    }
  }
}

adampbutler avatar Dec 24 '21 01:12 adampbutler