webdriverio/webdriverio

[🐛 Bug]: `unhandledPromptBehavior` has no effect

Open

#14.120 aberto em 28 de jan. de 2025

Ver no GitHub
 (3 comments) (1 reaction) (0 assignees)JavaScript (6.029 stars) (1.793 forks)batch import
Bug 🐛help wanted

Description

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

9.7.1

Node.js Version

v22.13.1

Mode

WDIO Testrunner

Which capabilities are you using?

capabilities: [
        {
            browserName: 'chrome',
            unhandledPromptBehavior: "ignore",
        },
        {
            browserName: 'firefox',
            unhandledPromptBehavior: "ignore",
        },
    ],

What happened?

The page displays an alert(). I want to check if it has the correct text. The message box is opened briefly and then closed again.

Chrome is able run an assertion when the assertion is made right after the alert is opened. Firefox isn't. And if the alert comes at an unknown time, we cant assert at all.

When I debug the tests and click the button to open the alert, the alert is immediately dismissed in chrome. In Firefox it does not show up at all.

What is your expected behavior?

The alert should stay open until I explicitly accept or dismiss it.

How to reproduce the bug.

I created a repository where I reproduce wdio bugs: https://github.com/htho/wdio-repro-collection

Just git clone, npm i & npm run test:alert

For completeness sake, here is some code:

https://github.com/htho/wdio-repro-collection/blob/main/docs/alert.html#L8-L11

<body>
    <button id="alert" onclick="alert('my alert')">Show Alert</button>
    <button id="delayedAlert" onclick="setTimeout(() => alert('my alert'), 1000)">Show Delayed Alert</button>
</body>

https://github.com/htho/wdio-repro-collection/blob/main/test/specs/alert.e2e.ts


import { expect, browser } from '@wdio/globals'

beforeEach(async () => {
    await browser.url(`https://htho.github.io/wdio-repro-collection/alert.html`)
});

describe('alert', () => {
    it.skip("can be debugged", async () => {
        await browser.debug();
    });
    it("can be tested", async () => {
        await $("#alert").click();
        await expect(browser.getAlertText()).resolves.toBe("my alert");
    });
    it("fails with wrong value", async () => {
        await $("#alert").click();
        await expect(() =>
            expect(browser.getAlertText()).resolves.toBe("bar")
        ).rejects.toThrowError(/my alert/g);
    });
    it("should be pausable and then tested (but it isn't)", async () => {
        await $("#alert").click();
        await browser.pause(2_000);
        await expect(browser.getAlertText()).resolves.toBe("my alert");
    });
});
describe('delayedAlert', () => {
    it("can be tested", async () => {
        await $("#delayedAlert").click();
        await expect(browser.getAlertText()).resolves.toBe("my alert");
    });
    it("fails with wrong value", async () => {
        await $("#delayedAlert").click();
        await expect(() =>
            expect(browser.getAlertText()).resolves.toBe("bar")
        ).rejects.toThrowError(/my alert/g);
    });
    it("should be pausable and tested (but it isn't)", async () => {
        await $("#delayedAlert").click();
        await browser.pause(2_000);
        await expect(browser.getAlertText()).resolves.toBe("my alert");
    });
});

Relevant log output

Not sure what is relevant here.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

Guia do colaborador