codeceptjs / codeceptjs/CodeceptJS

Puppeteer fails subsequent tests if beforeunload popup shown

Abierto
#3,068 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
JavaScript
Estrellas
4.2k
Forks
757
Merge medio
2 d 9 h
PR fusionados (30 d)
16

Descripción

#### What are you trying to achieve?
When testing a page which shows a popup on unload (`beforeunload` event), CodeceptJS fails if `restart: false` is set.

The issue is not present when `restart: true` is set.

Additionally, process exits with code 0, indicating a success.

I couldn't successfully accept the popup, and I tried at the end of the first test, at the beginning on the second test, and in `_before` handler.

Example project: https://github.com/dejanceltra/codeceptjs-popup-issue
CodeceptJS run: https://github.com/dejanceltra/codeceptjs-popup-issue/runs/3836071868

#### What do you get instead?

```bash
npx codeceptjs run
shell: /usr/bin/bash -e {0}
creating output directory: /home/runner/work/codeceptjs-popup-issue/codeceptjs-popup-issue/output
CodeceptJS v3.1.3
Using test root "/home/runner/work/codeceptjs-popup-issue/codeceptjs-popup-issue"

test --

✔ test something in 133ms
Popup already exists and was not closed. Popups must always be closed by calling either I.acceptPopup() or I.cancelPopup()

✖ test something 2 in 109ms
Error processing test.passed event:
TypeError: Cannot convert undefined or null to object
at EventEmitter. (/home/runner/work/codeceptjs-popup-issue/codeceptjs-popup-issue/node_modules/codeceptjs/lib/listener/steps.js:55:5)
at EventEmitter.emit (node:events:402:35)
at Object.emit (/home/runner/work/codeceptjs-popup-issue/codeceptjs-popup-issue/node_modules/codeceptjs/lib/event.js:145:28)
at /home/runner/work/codeceptjs-popup-issue/codeceptjs-popup-issue/node_modules/codeceptjs/lib/scenario.js:96:15

✖ test something 2 in 109ms

-- FAILURES:

1) test
test something 2:
Uncaught Cannot accept dialog which is already handled!
at Object.assert (node_modules/puppeteer/lib/cjs/puppeteer/common/assert.js:26:15)
at Dialog.accept (node_modules/puppeteer/lib/cjs/puppeteer/common/Dialog.js:79:21)
at /home/runner/work/codeceptjs-popup-issue/codeceptjs-popup-issue/node_modules/codeceptjs/lib/helper/Puppeteer.js:483:25

Scenario Steps:
- I.amOnPage("https://example.com") at Test. (./test_test.js:9:7)

2) test
test something 2:
Error: done() called multiple times in test of file /home/runner/work/codeceptjs-popup-issue/codeceptjs-popup-issue/test_test.js
at /home/runner/work/codeceptjs-popup-issue/codeceptjs-popup-issue/node_modules/codeceptjs/lib/scenario.js:99:41

FAIL | 1 passed, 2 failed // 1s
Run with --verbose flag to see complete NodeJS stacktrace
```

> Provide test source code if related
```html

window.addEventListener("beforeunload", function(event) {
event.returnValue = "message";
});

```
```js
Feature('test');

Scenario('test something', ({ I }) => {
I.amOnPage(`file://${process.cwd()}/test.html`);
});

Scenario('test something 2', ({ I }) => {
I.amOnPage('https://example.com');
});
```

### Details

* CodeceptJS version: 3.1.2
* NodeJS Version: v16.9.1
* Operating System: macOS | Linux
* puppeteer: 10.4.0
* Configuration file:

```js
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: {
restart: false,
url: 'http://localhost',
show: false,
windowSize: '1200x900'
}
},
bootstrap: null,
mocha: {},
name: 'puppeteer-test',
plugins: {
pauseOnFail: {},
retryFailedStep: {
enabled: true
},
tryTo: {
enabled: true
},
screenshotOnFail: {
enabled: true
}
}
}
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.