Testing / Karate Framework Interview questions
1. What is the Karate Framework?
Karate is an open-source test automation framework, built and maintained by Karate Labs, that combines API testing, mocking, performance testing, and UI automation into a single tool using one consistent syntax. It's built on Gherkin (the same Given/When/Then style Cucumber uses) but doesn't requ...
2. What is a Karate feature file?
A feature file is a plain-text file with a .feature extension that contains one or more test scenarios written in Karate's Gherkin-based syntax. It's the fundamental unit of a Karate test suite, similar in spirit to a Cucumber feature file, but Karate interprets the steps directly rather than map...
3. What is the purpose of the Given, When, Then keywords in Karate?
Given , When , and Then are Gherkin keywords that structure a scenario into setup, action, and verification, and And / But continue whichever section they follow. In Karate specifically, these keywords aren't just readability sugar, they map directly to built-in steps Karate understands natively....
4. What is the match keyword used for in Karate?
match is Karate's core assertion keyword, used to compare an actual value (commonly a JSON or XML response) against an expected value or pattern. It supports deep, structural comparison of JSON and XML out of the box, without needing an external assertion library. * match response == { id: 1, nam...
5. What is the def keyword used for in Karate?
def declares a variable within a scenario, which can hold a JSON object, an array, a primitive value, or even a JavaScript function, since Karate's variables are backed by its embedded JavaScript engine. * def userId = 42 * def payload = { name: 'Alice' , role: 'admin' } * def greet = function(na...
6. What is a Background section in a Karate feature file?
A Background section contains steps that run before every scenario in a feature file, useful for shared setup like defining the base URL, common headers, or reusable variables that every scenario in the file needs. Feature: order API tests Background: * url 'https://api.example.com' * header Auth...
7. What is a Scenario Outline in Karate?
A Scenario Outline defines a single scenario template with placeholder values, then runs it once per row of data supplied in an accompanying Examples table, avoiding the need to copy-paste near-identical scenarios for each input variation. Scenario Outline: create a user with different roles Give...
8. What are Karate's built-in type markers, like #number and #string?
Type markers are special string values Karate recognizes inside a match expression to assert on a value's type or shape rather than its exact value, which matters for fields like IDs, timestamps, or UUIDs that are unpredictable but still need validating. Marker Meaning #number Value must be a num...
9. What is karate-config.js used for?
karate-config.js is Karate's global configuration file, executed once before any test runs, used to define variables and settings shared across the entire test suite, most commonly environment-specific values like base URLs or credentials. function fn() { var env = karate.env || 'dev' ; var confi...
10. What are tags used for in Karate?
Tags are @ -prefixed labels placed above a Feature or Scenario that let a test run be filtered to include or exclude specific groups of tests, without commenting out or physically separating files. @smoke Scenario: basic health check Given url baseUrl + '/health' When method get Then status 200 @...
11. What is the call keyword used for in Karate?
call invokes another feature file (or a JavaScript function) from within a scenario, letting common setup logic, like an authentication flow that gets a token, be written once and reused across many feature files instead of duplicated in every one. Background: * def loginResult = call read( 'logi...
12. What is Karate's assert keyword?
assert evaluates a JavaScript boolean expression and fails the step if it evaluates to false, serving as the general-purpose escape hatch for conditions that don't fit neatly into a structural match comparison. * def price = response . price * assert price > 0 * assert response . items . length <...
13. What is the configure keyword used for in Karate?
configure sets runtime behavior for the HTTP client and other engine settings, either globally in karate-config.js or scoped to a single feature or scenario. Common uses include setting default headers, timeouts, SSL behavior, and retry settings. * configure headers = { Accept: 'application/json'...
14. What are the main features of the Karate Framework?
Karate's value proposition centers on covering several distinct testing needs with one tool and one syntax, rather than assembling separate libraries for each. API testing - REST, GraphQL, and SOAP requests with built-in JSON/XML assertions, no glue code required. Mocking - stand up stateful, loc...
15. What is Karate's built-in mock server used for?
Karate's mock server lets a feature file define HTTP request/response behavior and serve it as a real, running HTTP endpoint, useful for testing a service in isolation from dependencies that are slow, unreliable, or simply not available in a given test environment. Scenario: pathMatches( '/users/...
16. What is Karate's UI automation driver used for?
Karate's built-in driver automates browser interactions, clicking, typing, navigating, and asserting on page content, using the same feature-file syntax as API tests, so a team testing both an API and its UI can share tooling, reporting, and conventions instead of maintaining a separate framework...
17. What is Karate-Gatling integration used for?
Karate's Gatling integration lets existing functional API test scenarios be reused directly for load and performance testing, instead of rewriting the same request logic a second time in a separate performance-testing tool. The same feature file that verifies an endpoint returns the correct data ...
18. What is the path keyword used for in Karate?
path appends one or more path segments to the current base URL, typically used to build the specific resource path for a request, and can accept multiple comma-separated segments or dynamic variables. Given url baseUrl And path 'users', userId, 'orders' When method get # results in: GET {baseUrl}...
19. What is the header keyword used for in Karate?
header sets a single HTTP header on the request about to be made, commonly used for things like Authorization , Content-Type , or any custom header a particular API expects. Given url 'https://api.example.com/users' And header Authorization = 'Bearer ' + authToken And header Content-Type = 'appli...
20. What is Karate's embedded JavaScript engine, karate-js?
karate-js is Karate's own, purpose-built JavaScript engine, written from scratch in Java specifically for Karate's needs, replacing the previously used GraalJS engine (which itself had replaced the now-deprecated Nashorn engine in earlier Karate versions). The motivation for building a custom eng...
21. What is the eval keyword in Karate?
eval executes an arbitrary JavaScript expression or statement as a step, used for logic or side effects that don't fit into def , match , or assert , such as logging, mutating shared state, or calling a function purely for its side effect rather than to capture a return value. * eval karate . log...
22. What is the retry until keyword used for?
retry until repeatedly executes an HTTP call (and optionally other steps) until a given condition becomes true or a configured retry limit is reached, useful for polling an endpoint whose result depends on asynchronous processing that hasn't necessarily finished by the time the first request is m...
23. What is a Karate Runner class?
A Runner class is the Java entry point used to execute Karate feature files from a build tool or IDE, most commonly invoked through JUnit. It specifies which features (and optionally which tags) to run and how many should execute in parallel. import org.junit.jupiter.api.Test ; import com.intuit....
24. What is Karate CLI?
Karate CLI is a single-binary command-line launcher for running Karate tests without requiring a Maven or Gradle project setup, aimed at teams or individuals who want to run .feature files directly, such as for quick exploratory testing, scripting, or non-Java environments. karate tests/users.fea...
25. What is Karate Agent?
Karate Agent is an AI-assisted testing capability from Karate Labs that authors and maintains tests from natural-language descriptions, interacting through an IDE, the Model Context Protocol (MCP), or directly with the test suite, aimed at reducing the manual effort of writing and updating tests ...
26. Explain the execution flow of a Karate scenario from feature file to HTTP response?
When a scenario runs, Karate processes its steps sequentially, building up request state before finally triggering the HTTP call, then applying the assertions that follow. sequenceDiagram participant Runner as Karate Runner participant Engine as Karate Engine (karate-js) participant HTTP as HTTP ...
27. Why does Karate not require step definitions like traditional Cucumber?
Traditional Cucumber treats Gherkin purely as a human-readable specification layer: every step, however simple, needs a corresponding piece of glue code (a step definition) written in Java, Ruby, or whatever language the project uses, that implements what that step actually does. Karate takes a d...
28. How does Karate differ from REST Assured for API testing?
REST Assured is a Java library: tests are written as Java code using a fluent, chainable API, which means writing REST Assured tests requires a Java development setup and Java language proficiency. Karate tests are written in Gherkin-based feature files, readable and writable by people without a ...
29. What is the difference between match == and match contains in Karate?
match == requires the actual value to be exactly equal to the expected value, every key in a JSON object (or every element in an array) must be present and match, with nothing extra and nothing missing. match contains only requires the expected keys or elements to be present, in any order, withou...
30. How do you implement data-driven testing using Scenario Outline and Examples in Karate?
A Scenario Outline paired with an Examples table is the standard way to run the same logical test against many different inputs, with each table row substituting into placeholders written in angle brackets throughout the scenario's steps. Scenario Outline: validate login with different credential...
31. When should you use callonce instead of call?
call executes the referenced feature (or function) every time that step is reached, once per scenario. callonce executes it exactly once for the entire test run (or the entire feature, depending on scope) and caches the result, reusing that cached result for every subsequent scenario instead of r...
32. How do you troubleshoot a failing match assertion in Karate?
Karate's failure output for a match is usually specific enough to pinpoint the exact mismatched field, but a few systematic checks help when the cause isn't immediately obvious. Read the mismatch path and message carefully - Karate reports the JSON path of the specific field that didn't match, al...
33. Why did Karate replace GraalJS with its own custom JS engine (karate-js)?
Karate's JavaScript engine has changed twice in its history: originally Nashorn (bundled with the JDK), then GraalJS after Oracle deprecated Nashorn, and more recently karate-js, a JavaScript engine written from scratch specifically for Karate. The driving reason for the second migration was conc...
34. How does Karate handle parallel test execution using virtual threads?
Newer versions of Karate run on Java 21+ and use virtual threads, a lightweight concurrency mechanism introduced in modern Java, to execute large numbers of scenarios in parallel with far less overhead than traditional OS-backed thread pools require. Karate testAll() { return Karate.run("classpat...
35. Explain the internal working of the @lock tag for controlling parallel execution?
Some scenarios genuinely can't run safely at the same time as others, most often because they touch a shared, stateful resource like a specific database row or an external system that doesn't tolerate concurrent writes. The @lock tag provides fine-grained mutual exclusion for exactly these cases,...
36. What is the difference between Karate and Postman for API testing?
Postman is primarily a GUI-based tool for manually exploring and calling APIs, with scripting (via JavaScript in pre-request/test scripts) layered on top for automation. Karate is a code-first, text-based automation framework designed from the ground up for repeatable, version-controlled, CI-inte...
37. How do you implement reusable authentication flows using call in Karate?
Authentication is one of the most common candidates for reuse across a Karate suite, since nearly every scenario touching a protected endpoint needs a valid token, but the login flow itself shouldn't be copy-pasted into every feature file. # login.feature Feature: reusable login Scenario: Given u...
38. Why use Karate for performance testing instead of a dedicated tool like JMeter alone?
JMeter and similar dedicated performance tools are powerful but require building and maintaining a separate set of test scripts, typically in a different format or UI than the functional API tests already exist as, which means the two suites can drift apart as the API evolves. Karate's Gatling in...
39. What is the difference between match contains and match contains only?
match contains checks that the actual value includes at least the specified elements or keys, allowing additional elements the assertion doesn't mention. match contains only is stricter: it requires the actual value to contain exactly the specified elements, no extras, but without caring about th...
40. How does Karate's mock server handle stateful request/response scenarios?
Because a Karate mock feature is really just a set of scenarios matched against incoming requests, and each scenario has full access to Karate's variable and JavaScript capabilities, a mock can maintain state across multiple requests within a single test run, not just return a fixed canned respon...
41. When would you choose Karate's UI driver over a separate Selenium-based framework?
Karate's UI driver makes the most sense when a team already uses Karate for API testing and wants UI tests to share the same syntax, reporting, and CI integration rather than maintaining a second, unrelated framework and toolchain just for browser automation. It's also a strong fit for workflows ...
42. How do you configure environment-specific settings using karate.env?
karate.env is a system property that karate-config.js reads to decide which environment's configuration values (base URLs, credentials, feature flags) to return, letting the same test suite target different environments without editing any feature files. // karate-config.js function fn() { var en...
43. What is the difference between Karate v1's @parallel=false and v2's @lock tag?
Both exist to prevent unsafe concurrent execution of scenarios that touch shared, contended resources, but they differ sharply in granularity. @parallel=false (v1) @lock (v2) All-or-nothing: opts a tagged scenario out of parallel execution entirely. Fine-grained: only serializes scenarios that sh...
44. Explain the internal working of Karate's CDP-based browser automation?
Rather than depending on a separate WebDriver binary acting as a translation layer between test code and the browser, Karate's driver for Chrome, Chromium, and Edge speaks the Chrome DevTools Protocol (CDP) directly, communicating with the browser over a WebSocket connection the browser itself ex...
45. How do you optimize a large Karate regression suite for faster execution?
Most of the runtime cost in a large suite comes down to how much actually runs in parallel, how much redundant setup happens per scenario, and how much time is spent waiting rather than executing. Tune parallelism - increase the Runner's .parallel(n) value to take advantage of virtual threads, si...
46. What is the difference between karate-config.js and a feature-level Background?
Both set up shared state before tests run, but at very different scopes: karate-config.js runs once, globally, before the entire test suite, while a Background runs once per scenario, scoped to a single feature file. karate-config.js Background Runs once for the whole suite. Runs before every sce...
47. How does the Karate Runner decide which features and tags to execute?
The Runner determines what to run based on a combination of the classpath/path expression given, an optional tag expression, and any additional filtering configured on the run. Karate testSuite() { return Karate.run("classpath:tests") .tags("@regression", "~@wip") .parallel(50); } The path expres...
48. Why should you use table-driven Examples instead of hardcoding multiple scenarios?
Copy-pasting a scenario multiple times with slightly different literal values works, but it multiplies maintenance cost: any change to the underlying steps (a renamed field, an extra header, a different assertion) has to be applied identically across every duplicated copy, and it's easy for copie...
49. What is the difference between path and param keywords in Karate?
path appends segments directly into the URL's path portion, while param adds a key-value pair to the URL's query string. Mixing the two up produces a request to the wrong URL shape entirely, even if both look similar at a glance in the feature file. Given url baseUrl And path 'users', userId And ...
50. How do you troubleshoot flaky UI tests in Karate, and how does v2's automatic waiting help?
UI test flakiness usually comes down to timing: the test tries to interact with an element before the page has actually finished rendering or updating it, and older automation approaches often required explicit manual waits sprinkled throughout the test to compensate. Confirm whether automatic wa...