Рет қаралды 822
00:00 Intro
00:40 Add new class for API Testing
05:45 3 basic parts of Gatling simulation script
07:51 GET API scenario setup
19:59 POST API scenario setup
29:24 Refer POST API body from a file
35:18 PUT API scenario setup
38:41 DELETE API scenario setup
41:20 Feeders (Parameterization)
41:51 Feeders demo
48:15 Feeders strategy
58:18 Running actual request with Feeders
01:07:04 Summary and next steps
API Testing
API Testing Steps
Step 1 - Add a new class
Step 2 - Extend from Gatling Simulation class
Step 3 - Import required Gatling libraries
Step 4 - Create sections for Protocol, Scenario, SetUp
Step 5 - Add checks as needed
Step 6 - Run and check Report
Get API Demo
Post, Put, Delete API Demo
Step 1 - Add a new class
Step 2 - Extend from Gatling Simulation class
Step 3 - Import required Gatling libraries
Step 4 - Create sections for Protocol, Scenario, SetUp
Step 5 - Add scenario and request with headers & body as needed
Step 6 - Refer request body (payload) from file using
Step 7 - Add checks as needed
Step 8 - Run and check Report
// post, put api example
.exec(
http("Put request")
.post("/users/2")
.asJson
.body(StringBody(
"""{
| "name": "Raghav",
| "job": "zion resident"
|}""".stripMargin))
.check(
status is 200,
jsonPath("$.name") is("John")
)
)
// post, put api example (body from file)
.post("/users")
.asJson
.header("content-type", "application/json")
.body(RawFileBody("data/data.json"))
// delete api example
.exec(
http("delete req")
.delete("/users/2")
.check(status is 200)
)
Feeders (Parameterization)
What are Feeders
Data sources like csv, json files to store test data
How to use Feeders
Step 1 - Create a test data file (csv) and add data as needed for the test
Step 2 - Declare feeder in script with feeder strategy
Java example
FeederBuilder.Batchable<String> feeder = csv("search.csv").random();
Scala example
val feeder = csv("search.csv").random
Kotlin example
val feeder = csv("search.csv").random()
queue - default
- takes value in a queue (sequentially)
- will throw error if it runs out of lines
shuffle
- works like queue, but values are chosen randomly
- will throw error if it runs out of lines
random
- chooses values randomly
- same values can be chosen several times
- will NOT throw error on end of line
circular
- takes the values as in the feeder in order
- on reaching last value, returns to the first value
Step 3 - Add feed step in scenario .feed(feeder)
val scn = scenario("Feeder demo")
.feed(feeder)
.exec { session =>
println("Name : "+session("name").as[String])
println("Job : "+session("job").as[String])
session
}
Note : Every time we use the function feed(feeder) it gets next row from csv
val scn = scenario("Feeder demo")
.feed(feeder)
.exec { session =>
println("Name: "+session("name").as[String])
println("Job: "+session("job").as[String])
session
}
.pause(1)
.feed(feeder)
.exec { session =>
println("Name : "+session("name").as[String])
println("Job : "+session("job").as[String])
session
}
Note : Can use repeat() function
val scn = scenario("Feeder demo")
.repeat(3) {
feed(feeder)
.exec { session =>
println("Name: " + session("name").as[String])
println("Job: " + session("job").as[String])
session
}
}
Step 4 - To refer any data from csv file use syntax #{columnName}
.feed(feeder)
.exec(http("Search")
.get("/computers?f=#{columnName}")
How to use Feeders
Every time we use the function feed(feeder) it gets next row from csv
If the strategy is random or circular, the rows will get recycled and No Error will be thrown
Can increase users to use multiple sets of data from csv
Can use repeat() function
▬▬▬▬▬▬▬
Document - tinyurl.com/GatlingDoc1-Ragha...
Share with all who may need this
If my work has helped you, consider helping any animal near you, in any way you can
Never Stop Learning
Raghav Pal
AutomationStepByStep.com/
-