Testing / Karate Framework Interview questions
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 Authorization = 'Bearer ' + authToken Scenario: get an order Given path '/orders/1' When method get Then status 200 Scenario: create an order Given path '/orders' And request { item: 'Widget', qty: 2 } When method post Then status 201
Because the Background runs fresh before each scenario, not once for the whole file, any state it sets up (like a freshly generated auth token) is guaranteed consistent for every scenario, avoiding the kind of test pollution that can happen when setup only runs once for an entire suite.
More Related questions...