codeceptjs / codeceptjs/CodeceptJS

Puppeteer fails subsequent tests if beforeunload popup shown

Ouverte
#3,068 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
JavaScript
Étoiles
4.2k
Forks
757
Merge moyen
2 j 9 h
PR mergées (30 j)
16

Description

#### 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
}
}
}
```

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Reproduce the restart:false scenario from the provided HTML and JavaScript snippets, then inspect lib/helper/Puppeteer.js around the dialog handling reported at line 483 and lib/listener/steps.js around line 55. Verify that a beforeunload popup does not break the following test or cause duplicate completion errors, and confirm the run reports the correct failure status.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript
Domaine
testing
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.