Using Karate hooks
Hooks are a special mechanism to allow events to be received from test runs and run code in reaction to them. In this example, we will use hooks to output some information about scenarios and steps while tests are executed.
To use hooks, you need to do two things:
- Implement a
Java
class implementing Karate’s hook interface:com.intuit.karate.RuntimeHook
. - Register the new hook class as a Karate hook in your runner class.
In the following sections, we go through both steps.
Implementing a new hook class
In our example, we want to add some more log outputs that tell us which scenario is started and finished and what each step result is. For this, we can start with a class implementing Karate’s RuntimeHook
interface like this:
package hooks; import com.intuit.karate.RuntimeHook; public class KarateHooks implements RuntimeHook { }
In our example project, this class is called KarateHooks
and resides in the hooks
package on...