karatelabs/karate · error · DriverException
unknown window operation
Error message
unknown window operation: {operation} What it means
Driver.window(String) dispatches a named window operation to maximize/minimize/fullscreen/normal. Any other string throws this DriverException listing the unknown operation. The set of operations is intentionally closed so invalid operation names fail loudly rather than silently doing nothing.
Solutions
- Use one of: 'maximize', 'minimize', 'fullscreen', 'normal' (exact lowercase spelling)
- For resizing to specific dimensions call driver.setDimensions({ width: ..., height: ... }) instead of window()
- If the operation name comes from config, validate it against the four allowed values first
Example fix
// before
driver.window("Resize");
// after
driver.setDimensions(Map.of("width", 1024, "height", 768)); // or driver.window("maximize"); Defensive patterns
Strategy: validation
Validate before calling
java.util.Set<String> ops = java.util.Set.of("maximize","minimize","fullscreen","normal");
if (!ops.contains(operation)) throw new IllegalArgumentException("unknown window op: " + operation); Type guard
boolean isWindowOp(String op) { return java.util.Set.of("maximize","minimize","fullscreen","normal").contains(op); } Try / catch
try { driver.window(op); } catch (DriverException e) { if (e.getMessage().startsWith("unknown window operation")) { /* use setDimensions instead */ } else throw e; } Prevention
- Only pass the four documented lowercase operation names
- Use setDimensions for sizing instead of window()
- Centralize window operation names in constants
When it happens
Trigger: Calling driver.window("resize"), driver.window("Maximize") (wrong case), driver.window("fullScreen"), or passing a variable holding an unexpected value.
Common situations: Case-sensitivity mistakes; developers guessing operation names not in the enum-like set; scripts ported from other automation tools with different window API verbs; for arbitrary size changes, window operations are the wrong API (use setDimensions).
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- driver keyword requires a URL argument
- driver URL evaluated to null:
- element not found:
- missing array argument 'patterns':
- missing 'mock' or 'handler' in intercept config
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/8dfd95fffb09aba6.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/driver/Driver.java:571
switchFrame((String) null);
} else if (target instanceof Number n) {
switchFrame(n.intValue());
} else {
switchFrame(target.toString());
}
}
/**
* Window management. Dispatches to maximize(), minimize(), fullscreen().
*/
@Override
default void window(String operation) {
switch (operation) {
case "maximize" -> maximize();
case "minimize" -> minimize();
case "fullscreen" -> fullscreen();
case "normal" -> setDimensions(Map.of("windowState", "normal"));
default -> throw new DriverException("unknown window operation: " + operation);
}
}
/**
* Tab switching. Dispatches to {@link #switchPage(int)} or {@link #switchPage(String)}.
*/
@Override
default void tab(Object target) {
if (target instanceof Number n) {
switchPage(n.intValue());
} else {
switchPage(target.toString());
}
}
// ========== Navigation ==========
/**View on GitHub (pinned to a22eb90246)