In Karate framework how to call an API couple of times in background using callonce?

Viewed 54
Feature: Manage pets version#1

   Background:
     * def pet1 = call read('createPet.feature'){'cat'}
     * def pet2 = call read('createPet.feature'){'dog'}

   Scenario: Get single pet
   Scenario: Get all pets

Feature: Manage pets version#2

   Background:
     * def pet1 = callonce read('createPet.feature'){'cat'}
     * def pet2 = callonce read('createPet.feature'){'dog'}

   Scenario: Get single pet
   Scenario: Get all pets

I want to create 2 pets in the background but only once and all scenarios can use the same data. I know about callonce. If I use callonce as in version#2, for pet2 Karate is returning the response cached for pet1. I need to have two separate pets created and I want this data setup only once for the entire feature. How can I achieve this in Karate? Your help is greatly appreciated!!

1 Answers

Just re-design your test. Create a new feature createTwoPets.feature, call other features if needed and then use callonce.

Related