1

Here is a simple test that I am trying to run:

 Background:
    * def newCatReturned = karate.callSingle('./generate-cat-payload.feature')

  Scenario: Create a new cat
    * print '*** Cat  : ', newCatReturned.cat

    Given path '/cats'
    And request newCatReturned.cat
    When method post
    Then status 201
    And print responseHeaders['Location'][0]

Functional testing works fine. The challenge that I have is during the integrated gatling tests. Though the scenarios are run per the load parameters, the callSingle/callonce are run only once or the cat object returned is same across all invocations of the feaure during the gatling run.

Is there a way to accomplish this so that my PT tests produce different cat object for each iteration of the load? While I could use feeders, I would like to see if there is a single way to randomize payload for both functional and performance tests.

Appreciate any insights.

1 Answers1

1

Just create a Java class with a static method that does what you want. Use that in your Karate feature. For e.g. Utils.getCat()

But using a Gatling feeder is the recommended approach.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Thank you, Peter! I converted to static method and it resulted in a different behavior. First the usecase that I posted got addressed. However, the variable newCatReturned is reset with every scenario. There are 2 scenarios that I am trying, the first one to create the cat, and second one to search the cat. When I attempt to search the cat, since the static method returns a different object, that test is failing. Is there a way to make this static method call to be only once per feature instead of for every scenario? – Amaresh Kulkarni Jul 14 '23 at 21:21
  • I think it ultimately boils down to this guidance in documentation: Keep in mind that you should be able to comment-out a Scenario or skip some via tags without impacting any others. Note that the parallel runner will run Scenario-s in parallel, which means they can run in any order. If you are looking for ways to do something only once per feature or across all your tests, see Hooks. – Amaresh Kulkarni Jul 14 '23 at 22:19
  • I ended up combining create and get to verify the creation, and both functional and pt work fine now. Gatling was still separating out the API call performance metrics, so I guess this option works for me. Thanks again – Amaresh Kulkarni Jul 14 '23 at 22:25
  • 1
    @AmareshKulkarni that sounds like the right approach. I think you could have modified the static method to take a parameter to "signal" if it should be a new or existing object – Peter Thomas Jul 15 '23 at 01:34