karatelabs/karate · error · DriverException
inputFile: file not found
Error message
inputFile: file not found: {ref} (resolved to: {path}) — a bare path is relative to the feature, a leading '/' anchors the project root, 'file:' is a host machine path What it means
Thrown by DriverApi.resolveFilePath (via fileNotFoundMessage) when the ref resolved to a candidate local path but the file does not exist. Unlike the unresolvable-path variant, this includes the resolved path so you can see exactly where Karate looked.
Solutions
- Check the '(resolved to: ...)' path in the message and verify the file exists there
- Fix the relative path or use a leading '/' to anchor at the project root
- Use the 'file:' prefix with an absolute host path as a last resort
- Ensure fixture files are in the classpath output (target/test-classes) at test time
Example fix
// before
driver.inputFile("fixtures/photo.png", "#upload"); // resolved to wrong dir
// after
driver.inputFile("/src/test/resources/fixtures/photo.png", "#upload");
// or absolute:
driver.inputFile("file:/home/dev/fixtures/photo.png", "#upload"); Defensive patterns
Strategy: validation
Validate before calling
String resolved = featureDir.resolve("fixtures/photo.png").normalize().toString();
if (!java.nio.file.Files.exists(java.nio.file.Paths.get(resolved))) {
throw new IllegalStateException("fixture missing at: " + resolved);
}
driver.inputFile(resolved, "#upload"); Try / catch
try {
driver.inputFile(ref, "#upload");
} catch (DriverException e) {
if (e.getMessage().contains("(resolved to:")) {
String lookedAt = e.getMessage().replaceAll(".*resolved to: ([^)]+)\).*", "$1");
System.err.println("Karate looked at: " + lookedAt);
} throw e;
} Prevention
- Read the '(resolved to: ...)' hint in the message and check that exact path
- Mind Linux case sensitivity in file names
- Anchor with leading '/' for project-root files
- Confirm fixtures are copied to target/test-classes
When it happens
Trigger: driver.inputFile(ref, ...) where ref resolved (feature-relative or project-root) to a concrete local path but no file exists there; wrong filename, wrong directory, file deleted by a clean build, or the leading '/' anchoring to an unexpected root.
Common situations: Files under src/test/resources not on the runtime classpath, features moved between directories, clean builds wiping generated fixtures, case-sensitivity mismatches on Linux.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- inputFile: file not found
- inputFile not supported by this driver
- inputFile: not a local file
- inputFile: element did not resolve to a DOM node
- inputFile failed: | locator: | files
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/0420e4283c1ea07b.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/driver/DriverApi.java:181
if (ref.startsWith(Resource.FILE_COLON)) {
return Path.of(Resource.removePrefix(ref)).toAbsolutePath().normalize().toString();
}
ScenarioRuntime runtime = ScenarioRuntime.currentOrNull();
Resource resource;
try {
resource = runtime != null && runtime.getFeatureRuntime() != null
? runtime.getFeatureRuntime().resolve(ref)
: Resource.path(ref);
} catch (Exception e) {
throw new DriverException(fileNotFoundMessage(ref, null), e);
}
Path path = resource.isFile() ? resource.getPath() : null;
if (path == null || path.getFileSystem() != FileSystems.getDefault()) {
throw new DriverException("inputFile: not a local file: " + ref
+ " — the browser needs a real file on disk; extract it first, or point at it with 'file:'");
}
if (!resource.exists()) {
throw new DriverException(fileNotFoundMessage(ref, path));
}
return path.toAbsolutePath().normalize().toString();
}
private static String fileNotFoundMessage(String ref, Path resolved) {
return "inputFile: file not found: " + ref
+ (resolved == null ? "" : " (resolved to: " + resolved.toAbsolutePath().normalize() + ")")
+ " — a bare path is relative to the feature, a leading '/' anchors the project root,"
+ " 'file:' is a host machine path";
}
/**
* Adapt a JS/Java callable argument to a {@code Supplier<Object>}.
* <p>Karate treats inline JS lambdas as first-class Java callables — the
* same pattern that powers {@code karate.filter(list, x => ...)}.
* This helper lets driver bindings route a callable argument to the
* {@code Supplier}-taking overload of a method (polled locally in
* karate-js) rather than coercing it to a string and shipping it off toView on GitHub (pinned to a22eb90246)