karatelabs/karate · error · RuntimeException
waitForHttp() needs a URL argument
Error message
waitForHttp() needs a URL argument
What it means
karate.waitForHttp(url) requires a URL as its first argument; calling it with zero arguments throws this RuntimeException immediately. It is a strict arity check protecting against a missing parameter.
Solutions
- Pass the URL string as the first argument: karate.waitForHttp('http://localhost:8080/health')
- Optionally pass a second Map argument for timeoutMs/pollMs configuration
- Define the URL variable before the call
Example fix
// before
karate.waitForHttp();
// after
karate.waitForHttp('http://localhost:8080/health', { timeoutMs: 60000 }); Defensive patterns
Strategy: validation
Validate before calling
// JS
if (!url) throw new Error('waitForHttp requires a url');
karate.waitForHttp(url); Type guard
// JS
function hasUrl(u) { return typeof u === 'string' && u.length > 0; } Try / catch
if (arguments.length === 0) throw new Error('call waitForHttp(url) with a URL string'); Prevention
- Always pass the URL as the first argument
- Keep timeout/poll overrides in the optional second map argument
- Define the URL variable before the call site
When it happens
Trigger: Invoking karate.waitForHttp() with no arguments from a JS block or feature file.
Common situations: Refactoring a call and dropping the argument; confusing waitForHttp() with a no-arg variant; calling it before defining the URL variable.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- waitForPort() needs host and port arguments
- eval() needs one argument
- expect() needs at least one argument
- remove() needs two arguments: variable name and path
- setXml() needs at least two arguments: name and xml
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/9ec7392d4554b97a.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java:1058
}
logger.info("*** exited socket wait successfully");
return true;
} catch (Exception e) {
throw new RuntimeException("stop() failed: " + e.getMessage(), e);
}
};
}
// ========== Wait Utilities ==========
/**
* karate.waitForHttp(url) - Wait for an HTTP endpoint to become available.
* Polls until a successful response (2xx or 3xx) is received.
*/
static JavaInvokable waitForHttp() {
return args -> {
if (args.length == 0) {
throw new RuntimeException("waitForHttp() needs a URL argument");
}
String url = args[0] + "";
int timeoutMs = 30000;
int pollMs = 250;
if (args.length > 1 && args[1] instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, Object> options = (Map<String, Object>) args[1];
if (options.containsKey("timeout")) {
timeoutMs = ((Number) options.get("timeout")).intValue();
}
if (options.containsKey("interval")) {
pollMs = ((Number) options.get("interval")).intValue();
}
}
long deadline = System.currentTimeMillis() + timeoutMs;
java.net.http.HttpClient httpClient = java.net.http.HttpClient.newBuilder()
.connectTimeout(Duration.ofMillis(pollMs))
.build();View on GitHub (pinned to a22eb90246)