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 :
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