Testing / Karate Framework Interview questions
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.
Scenario: create a user Given url 'https://api.example.com/users' And request { name: 'Alice', role: 'admin' } When method post Then status 201 And match response.id == '#number'
Given typically sets up the request (URL, headers, request body), When performs the action (usually the HTTP call via method), and Then verifies the outcome (status code, response content). Karate doesn't strictly enforce which keyword precedes which step, they're interchangeable at runtime, but following the convention keeps scenarios readable for anyone unfamiliar with the specific API being tested.
More Related questions...