Перейти к содержимому

Karate Reusability: call, callonce, Arguments, Background and Helpers | Karate API Testing #07

Code & Test Automation

0:00 / 0:00

Karate Reusability: call, callonce, Arguments, Background and Helpers | Karate API Testing #07

2 просмотра · 23 ч назад
Code & Test Automation
16 подписчиков
2 просмотра · 23 ч назад
Code & Test Automation |    / @codetestautomation   Stop copying the login into every scenario. In this Karate video we move the login into a reusable feature and call it, read the variables it returns, and see how a call without def shares its variables with the caller. Then we pass JSON arguments, read them with __arg and by name, and watch the usual create-user example fail for real with a 400 because the practice API requires an email. Next, shared setup in a Background, and the difference between call and callonce, counted in real login requests. Finally a small helper library: a create-user helper called with a JSON array, and an idempotent cleanup helper that accepts 204 or 404. Everything is run for real, twice, against the local practice API. Video 7 of 10 in Karate API Testing (Java), for fresher and experienced engineers: installation with Maven, the core Gherkin syntax, JSON matching, variables and karate-config.js, headers and authentication, data-driven tests, reusable features, mocking, parallel runs and reports, and CI/CD. CHAPTERS 0:00 Introduction 1:48 Calling another feature 5:17 Passing arguments 9:26 Background and shared setup 12:09 A helper library 16:19 Recap 17:19 Subscribe HOW THE DEMOS WERE MADE Every command, test run and terminal output in this video was run for real (Temurin JDK 21.0.13, Apache Maven 3.9.16, Karate 2.1.4 (io.karatelabs:karate-junit6), JUnit 6.1.3; Debian 13 Linux) in throwaway Maven + Karate projects created for this video, against a small practice API (plain JDK, no dependencies) running on localhost. Timestamps and durations in the output are whatever that run took. Every Maven command with output in this video was run for real, twice, against the local practice API. Nothing in this video is typed only. Any screen marked ILLUSTRATION is a simplified mockup, not a screenshot. PRACTICE Write a helper feature that gets one user by id and returns it. Call it with an id from a create call, then call it with an id that doesn't exist, and find out what status you get by running it. Practice tip: pause at each code and terminal scene, type the feature file yourself in your own Maven project, run it against the practice API, and compare your output with what you see on screen. Next video: #08 Mocking and Test Doubles with Karate. #Karate #APITesting #Java #TestAutomation #CodeAndTestAutomation Subscribe to Code & Test Automation for more Karate, API testing, coding and test automation tutorials:    / @codetestautomation