Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to ignore the background when runing a simulation using karate-gatling

I want to run performance test on my APIs, the problem is every test feature is linked with a background that I use to generate my Bearer Token, and I don’t want to run the simulation test on that background

I tried to tag my background and then modify my scala simulation in this way but it does not work :

import com.intuit.karate.gatling.PreDef._
import io.gatling.core.Predef._
import scala.concurrent.duration._

class PerformanceTest extends Simulation {

  val test = scenario("test").exec(karateFeature("classpath","~@ignorebackground"))

  setUp(
    test.inject(rampUsers(2) during (5 seconds))
  )

}

And this is my feature test file :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Feature: Give information about computers

  @ignorebackground
  Background: Sample test
    Given url 'http://computer-database.gatling.io/computers'
    And param f = 'macbook'
    When method get
    Then status 200

  Scenario: Sample test
    Given url 'http://computer-database.gatling.io/computers'
    When method get
    Then status 200

Does this mean we can’t tag a background step ? we can only tag features and scenarios ?

>Solution :

Yes you cannot tag the Background!

My suggestion is don’t solve this using tags. This is what being able to switch variable values using karate-config.js is designed for. What I would do is have a karate.env called perf and set a global flag e.g. perfMode: true.

Then you can do this in your Background:

Background:
* if (!perfMode) karate.callSingle('auth.feature')

And you can put your bearer token logic in auth.feature and properly re-use it in all features. In fact you should consider having this conditional logic in karate-config.js itself.

Refer the docs also: https://github.com/karatelabs/karate/tree/master/karate-gatling#karatecallsingle

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading