Testing / Karate Framework Interview questions
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('login.feature') { username: 'admin', password: 'secret' } * def authToken = loginResult.token Scenario: get protected resource Given url baseUrl + '/protected' And header Authorization = 'Bearer ' + authToken When method get Then status 200
The called feature receives whatever arguments are passed in as its own variables, and whatever it defines with def becomes available in the result object returned to the caller, which is how the calling scenario retrieves values (like the token above) produced by the called feature.
More Related questions...