Testing / Karate Framework Interview questions
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 config = { baseUrl: 'https://dev-api.example.com' }; if (env === 'staging') { config.baseUrl = 'https://staging-api.example.com'; } else if (env === 'prod') { config.baseUrl = 'https://api.example.com'; } karate.configure('connectTimeout', 5000); return config; }
The function returns a JSON object whose keys become globally available variables in every feature file, so switching environments (dev, staging, prod) becomes a matter of setting the karate.env system property rather than editing individual feature files.
More Related questions...