karatelabs/karate · error · RuntimeException

driver URL evaluated to null:

Error message

driver URL evaluated to null: 

What it means

After the `driver` step text is evaluated as a Karate/JS expression, the result must be a usable URL. If evaluation returns null (undefined variable, expression with no value), the executor cannot derive a URL string and throws this error including the original text. It is distinct from the blank-text case: here there WAS an expression, it just produced null.

Solutions

  1. Define the variable first: `def url = 'http://localhost:9222'` before the driver step
  2. Use a default: `driver karate.properties('my.url') || 'http://localhost:9222'`
  3. print the expression result to verify it is non-null
  4. Check the environment config file (karate.env) provides the expected property

Example fix

// before
* driver karate.properties('driver.url')
# after
* def driverUrl = karate.properties('driver.url') || 'http://localhost:9222'
* driver driverUrl
Defensive patterns

Strategy: validation

Validate before calling

* def driverUrl = karate.properties('driver.url') || 'http://localhost:9222'
* if (!driverUrl) karate.fail('driver URL not configured')

Type guard

function isNonEmptyString(v) { return typeof v === 'string' && v.length > 0; }

Prevention

When it happens

Trigger: `driver someVar` where someVar is undefined; an expression like `driver karate.properties('my.url')` where the system property is not set (evaluates to null); null-returning JS calls used as the URL.

Common situations: Missing environment/system properties in CI so karate.properties returns null; typos in variable names; assuming a previous configure step defines the URL variable when it does not.

Related errors


AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12). Data as JSON: /api/errors/30c2d26de96d4b5f. Report an issue: GitHub.

Appendix: source

Thrown at karate-core/src/main/java/io/karatelabs/core/StepExecutor.java:3088

    // ========== Browser Driver ==========

    /**
     * Execute the driver keyword - navigate to a URL.
     * Examples:
     * - driver 'http://localhost:8080'
     * - driver serverUrl + '/path'
     * - driver myUrl
     */
    private void executeDriver(Step step) {
        String text = step.getText();
        if (text == null || text.trim().isEmpty()) {
            throw new RuntimeException("driver keyword requires a URL argument");
        }

        // Evaluate the expression to get the URL
        Object result = runtime.eval(text.trim());
        if (result == null) {
            throw new RuntimeException("driver URL evaluated to null: " + text);
        }

        String url = result.toString();

        // Get the driver (initializes lazily if needed)
        io.karatelabs.driver.Driver driver = runtime.getDriver();

        // Navigate to the URL
        driver.setUrl(url);
    }

    // ========== Karate Expression Helpers ==========

    /**
     * Gets a response header value by name (case-insensitive).
     * V1 compatibility: "match header Content-Type contains '...'"
     * Returns the first value if header has multiple values, null if not found.
     */

View on GitHub (pinned to a22eb90246)