Testing / Karate Framework Interview questions
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 scenario in one feature file. |
| Defines variables available to every feature file in the project. | Defines variables/setup available only within its own feature file. |
| Ideal for environment-wide config like base URLs. | Ideal for feature-specific setup like a particular resource's common headers. |
In practice these two layer together: karate-config.js typically provides broad, environment-level values like baseUrl, and each feature file's Background builds on top of those globals with whatever setup is specific to the scenarios in that particular file, like a resource path prefix or a feature-specific auth flow.
More Related questions...