Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

scala - @karate How to pass parameter to a feature file in gatling simulation class?

Let's consider a scenario, we have to run the performance test for "create an account api" which takes input as header/path param "Auth token" and input data like user account name . So for above scenario we have 2 feature file as,

to run performance test for POST http://baseUrl/auth_param/create/input_data 1. One feature(e.g: generateAuth.feature) file which will have the auth token 2. Second feature(createAccount.feature) file which take parameter as a auth token, input data.

Here is my simulation class,

class <MyClass> extends Simulation {

  before {
    println("Simulation is about to start!")
  }
  val generateAuthTest = scenario("generateAuth").exec(karateFeature("classpath:path/generateAuth.feature")) 
  val createAccountTest = scenario("test").exec(karateFeature("classpath:path/createAccount.feature"))
  setUp(
    createAccountTest.inject(rampUsers(1) over (10 seconds))).maxDuration(1 minutes)
  after {
    println("Simulation is finished!")
  }
}

Here, can i read auth from generateAuth.feature file which is input for createAccount.feature file, so that i can pass as a parameter? Please suggest me how to pass parameters to createAccount.feature while calling in karateFeature method.

Let me put a requirement here,

let's say we have some feature files for CRUD operations on a particular data. Here how i go to write functional scenario,

  1. I will create new feature file to write a scenario
  2. just use CRUD files to test a SINGLE flow.

Now if i go for Performance test cases on individual operation, i feel there are 2 ways,

  1. Create new 4 performance test feature files (one for each CRUD method) and call these CRUD feature files in the respective test feature file. Finally we just call test feature files in the respective gatling simulation class. **(In this case, I will end up with creating more test feature files as well simulation classes for performance, which I want to avoid) **
  2. Just call CRUD files in the respective gatling simulation class and pass the required parameters to them.(In this case , we just need to create only 4 simulation classes and run them on the basic of operation like create,read,delete and so on)

Here just wanted to know 2nd way of performance test, is it achievable or not in karate and if yes please let me know how?

Summary- I think its achievable using 3rd feature file (extra) for individual use case but I do not want to make an extra feature file for each case so that I can avoid maintenance work and can take advantage of re-usability of existing feature file from functional test to performance test.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just use the normal Karate concepts such as karate-config.js

You can easily switch environments by setting the karate.env system property.

For example:

mvn test -DargLine="-Dkarate.env=e2e"

EDIT: after you edited your question, it is clear you have a SINGLE flow you want to test. please use a SINGLE feature. I suggest you move the generateAuth into the Background of the feature. Also refer to the docs on callSingle() for advanced options.

If you are expecting 2 feature files to magically share data that is not possible and not needed if you structure your tests correctly.

If you really really need this, please create a Java singleton and access it from each feature. Totally don't recommend this though.

EDIT: In Karate 0.9.0 onwards, you can call a single scenario within a feature if it has a tag:

classpath:animals/cats/create.feature@sometagname

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...