JavaScript prompt (window-based alert with input) auto-closes in CodeceptJS with Playwright + BDD — how to handle it?
I'm trying to handle a JavaScript prompt (window-based alert with input) dialog and input some text before accepting it. But the prompt seems to be automatically closing before I can interact with it, and the test just moves to the next step. Any idea how to handle this properly or prevent it from being auto-dismissed? Example code or tips would be really helpful. Thanks! im using Codeceptjs with playwright helper and BDD
The automatic dismissing seems to be Playwright feature: https://playwright.dev/docs/dialogs#alert-confirm-prompt-dialogs
In my case (reloading of a page in a text editor causes a browser alert and I need to handle it) the following stuff works for me. I'm using traditional Playwright tests (non BDD). But not sure about your "window-based alert with input".
Scenario("Reload the page and confirm to stay in the editor", () => {
// Automatically cancel the popup
I.amCancellingPopups();
// Reload page
// Note we can't use I.refreshPage() here, because it waits for the page to be fully loaded, but in this case the page loading is blocked by the popup
I.executeScript(() => {
location.reload();
});
// This only cleans up the popup in CodeceptJS state
I.cancelPopup();
I.seeElement(buttonsFragment.save);
});
Scenario("Reload the page and confirm to leave the editor", () => {
// Automatically accept the popup
I.amAcceptingPopups();
// Reload page
I.executeScript(() => {
location.reload();
});
// This only cleans up the popup in CodeceptJS state
I.acceptPopup();
// Verify we are on the iPlanner page
I.seeElement(tipCommonPage.header);
// Verify the Edit instrument dialog is closed
I.dontSeeElement(buttonsFragment.save);
});
This issue is stale because it has been open for 90 days with no activity.