karatelabs/karate · error · DriverException
dialog dismiss failed
Error message
dialog dismiss failed: {error} What it means
CdpDialog.dismiss() sends Page.handleJavaScriptDialog with accept=false and throws DriverException 'dialog dismiss failed: <error>' if CDP returns an error. As with accept, the usual cause is the dialog no longer existing when the command arrives.
Solutions
- Check isHandled() before dismissing to avoid double-handling
- Catch DriverException and treat it as success when the dialog already disappeared
- Ensure only one code path (event handler or test step) manages the dialog
- Add a small synchronization so handlers don't race the test's explicit dismiss
Example fix
// before
dialog.dismiss(); // may fail if already handled by event handler
// after
if (!dialog.isHandled()) {
dialog.dismiss();
} Defensive patterns
Strategy: validation
Validate before calling
if (dialog == null || dialog.isHandled()) {
return; // already dismissed or gone
} Type guard
boolean canDismiss(CdpDialog d) { return d != null && !d.isHandled(); } Try / catch
try { dialog.dismiss(); }
catch (DriverException e) {
if (e.getMessage().startsWith("dialog dismiss failed")) {
logger.info("dialog already handled elsewhere");
} else throw e;
} Prevention
- Single code path owns dialog dismissal (handler OR test, not both)
- Check isHandled() before dismissing
- Synchronize event handlers and explicit dismiss calls
- Accept disappearance races as benign in CI
When it happens
Trigger: Calling dismiss() after the dialog was already handled or auto-closed; page navigated away, destroying the dialog; a prior accept()/dismiss() on the same dialog object.
Common situations: Event handler (setupEventHandlers) dismissing a dialog the test already handled; double dismissal in chained scenario steps; timing races in CI where the browser closed the dialog first.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- dialog accept failed
- dialog is blocking Runtime.evaluate
- dialog handler did not resolve dialog, auto-dismissing
- page load complete but JS context not ready yet
- frame context not received via event, falling back to…
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/6f1878c10cdcda6d.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDialog.java:109
// to prevent retry attempts that will also fail
if (response.isError()) {
// Log but don't throw - the dialog is effectively handled (gone)
throw new DriverException("dialog accept failed: " + response.getError());
}
}
@Override
public void dismiss() {
if (handled) {
// Already handled - silently return to avoid race condition errors
return;
}
handled = true;
CdpResponse response = cdp.method("Page.handleJavaScriptDialog")
.param("accept", false)
.send();
if (response.isError()) {
throw new DriverException("dialog dismiss failed: " + response.getError());
}
}
@Override
public boolean isHandled() {
return handled;
}
@Override
public String toString() {
return "Dialog{type='" + type + "', message='" + message + "'}";
}
}
View on GitHub (pinned to a22eb90246)