Gatling Step by Step Masterclass | Part 4

  Рет қаралды 822

Automation Step by Step

Automation Step by Step

Күн бұрын

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

Пікірлер: 10
@xXMrThomasXx
@xXMrThomasXx 3 күн бұрын
You are the best teacher :) Thank you for all your work, this part is very usefull. I go to the part 5 :)
@RaghavPal
@RaghavPal 2 күн бұрын
You're very welcome
@dhinesh207
@dhinesh207 Ай бұрын
Hi Raghav, the video is really helpful for learning. One quick quesiton so in learning sessions we use direct API without authentication, but in real proj how this will be handled? That has login authentication layer? If you can explain how in performance tests that will injects 100's of users and will be authenticated it will be helpful. Thank you
@RaghavPal
@RaghavPal Ай бұрын
Dhinesh Handling authentication in API performance testing is crucial to ensure that your application behaves as expected under load. Let's dive into some strategies for handling authentication in performance tests: 1. Authentication and Authorization: - Authentication: This involves verifying the identity of users or systems accessing your API. Common authentication methods include API keys, OAuth tokens, or basic authentication (username/password). - Authorization: Once authenticated, the system checks whether the user has the necessary permissions to perform specific actions. Authorization ensures that users can only access resources they are authorized for. 2. Challenges in API Performance Testing: - Concurrency: In performance testing, you simulate multiple users concurrently accessing the API. This means you need to handle authentication for each user. - Statelessness: APIs are typically stateless, meaning they don't retain information about previous requests. Each request must carry its authentication credentials. 3. Strategies for Handling Authentication in Performance Tests: - Pre-Authentication: - Authenticate users before starting the performance test. Obtain valid tokens or credentials for each user. - Pros: Simple setup, realistic scenario. - Cons: May not reflect real-world scenarios where tokens expire or change during a session. - Dynamic Authentication: - Authenticate users dynamically during the test. - For example, use Gatling's session variables to store tokens and inject them into subsequent requests. - Pros: Realistic, handles token expiration. - Cons: Adds complexity to test scripts. - Token Pooling: - Create a pool of pre-authenticated tokens. - During the test, assign tokens to users from the pool. - Pros: Balances load, avoids excessive token generation. - Cons: Requires managing token pool. - Token Refresh: - Periodically refresh tokens during the test. - Pros: Realistic, handles token expiration. - Cons: Adds complexity, may impact performance. - User Impersonation: - Impersonate different users during the test. - Pros: Realistic, covers various user roles. - Cons: Requires maintaining user profiles. 4. Gatling-Specific Implementation: - In Gatling, you can use session variables to store authentication tokens or credentials. - Example (assuming OAuth token-based authentication): ```scala val scn = scenario("API Performance Test") .exec(http("Login") .post("/login") .formParam("username", "myuser") .formParam("password", "mypassword") .check(jsonPath("$.access_token").saveAs("accessToken"))) .exec(http("Authenticated Request") .get("/api/resource") .header("Authorization", "Bearer ${accessToken}")) ``` - Customize the above script based on your authentication method. Remember that performance testing is about simulating real-world scenarios, so choose an approach that aligns with your application's behavior. Ensure that your authentication mechanisms are thoroughly tested to avoid surprises in production
@testqa8250
@testqa8250 2 ай бұрын
Sir please let's me know how to stress/load test firebase push notification in jmeter or postman.?
@RaghavPal
@RaghavPal 2 ай бұрын
To stress/load test Firebase push notifications in JMeter or Postman, you'll need to simulate the sending of push notifications to a large number of devices. Here's a general approach for both tools: For JMeter: 1. Set Up JMeter: Install JMeter and open it to create a new test plan. 2. Add Thread Group: Configure the number of threads (users), loop count, and ramp-up period. 3. Add HTTP Request: This will simulate sending the push notification. - Method: POST - URL: `fcm.googleapis.com/fcm/send` - Headers: Add headers for `Content-Type` as `application/json` and `Authorization` as `key=YOUR_SERVER_KEY`. - Body: Add a JSON payload with the necessary fields like `to` (registration token), `notification` (notification payload), and `data` (data payload). 4. Add Listeners: To view the results of the test, add listeners like View Results Tree, Summary Report, etc. 5. Run Test: Execute the test plan and analyze the results. For Postman: 1. Set Up Postman: Open Postman and create a new request. 2. Configure Request: - Method: POST - URL: `fcm.googleapis.com/fcm/send` - Headers: Add headers for `Content-Type` as `application/json` and `Authorization` as `key=YOUR_SERVER_KEY`. - Body: Add a JSON payload similar to the one used in JMeter. 3. Send Request: Execute the request and observe the response. 4. Automate: To simulate multiple requests, you can use Postman's Collection Runner or write a script to automate the process. Note: Replace `YOUR_SERVER_KEY` with your actual server key from Firebase project settings. For detailed steps and configurations, you may refer to the official documentation of JMeter and Postman, or look for specific tutorials that guide through the process of setting up a load test for push notifications Remember, when performing load testing, ensure that you comply with Firebase's terms of service and avoid sending an excessive number of requests that could disrupt the service. ..
@arunpallayil9485
@arunpallayil9485 2 ай бұрын
#AskRaghav Hello, I'm Sorry for asking an unrelated question about your latest video. Thank you for all your efforts so far. Thanks a lot. I was searching your playlists for a series on Spring Boot + Cucumber for API Testing. I could see the one using RestAssured, but I wanted to learn how to use just Spring Boot + Cucumber for BDD (API testing) without TestNG or RestAssured. If you have anything, please share. Thanks. Have a great day!
@RaghavPal
@RaghavPal 2 ай бұрын
Arun as of now I have not create on that. will plan.. can check all tutorials here - automationstepbystep.com/
@user-iv8tx3zz9s
@user-iv8tx3zz9s Ай бұрын
case classes must have a parameter list; try 'case class Simulation()' or 'case object Simulation' case class Simulation{ 👆 always comes this error
@RaghavPal
@RaghavPal Ай бұрын
The error message you're encountering in Gatling suggests that your `case class Simulation` is missing a parameter list. In Scala, case classes are special types of classes that are immutable and compared by value. They must have at least one parameter; otherwise, you should declare them as a `case object` if they do not have any parameters. Here's how you can correct the error: If your `Simulation` class does not need to take parameters, you can declare it as a `case object` like this: ```scala case object Simulation { // Your code here } ``` If your `Simulation` class needs to take parameters, you should include them in the declaration, for example: ```scala case class Simulation(param1: Type1, param2: Type2) { // Your code here } ``` Make sure to replace `Type1` and `Type2` with the actual data types you need, and `param1` and `param2` with the actual parameter names. If you're still facing issues, please ensure that your Scala version is compatible with the Gatling version you're using, as there might be compatibility issues between different versions..
Gatling Step by Step Masterclass | Part 5
1:21:19
Automation Step by Step
Рет қаралды 750
Gatling Step by Step Masterclass | Part 1
1:10:49
Automation Step by Step
Рет қаралды 2,4 М.
ХОТЯ БЫ КИНОДА 2 - официальный фильм
1:35:34
ХОТЯ БЫ В КИНО
Рет қаралды 2,6 МЛН
КАРМАНЧИК 2 СЕЗОН 6 СЕРИЯ
21:57
Inter Production
Рет қаралды 451 М.
ONE MORE SUBSCRIBER FOR 6 MILLION!
00:38
Horror Skunx
Рет қаралды 14 МЛН
FASTEST Way to Learn Coding and ACTUALLY Get a Job
8:50
Sahil & Sarra
Рет қаралды 7 МЛН
The easiest way to chat with Knowledge Graph using LLMs (python tutorial)
18:35
Shooting the Monstrously Powerful Quad M134 Minigun
2:16
Military Archive
Рет қаралды 3 МЛН
Gatling Beginners Tutorial | Correlation | Dynamic Referencing
20:42
Automation Step by Step
Рет қаралды 981
What are environment variables How do they work
30:14
Automation Step by Step
Рет қаралды 2,7 М.
100+ Computer Science Concepts Explained
13:08
Fireship
Рет қаралды 2,3 МЛН
Cypress Complete Beginners Masterclass 1 | Step by Step | Raghav Pal |
1:20:54
Automation Step by Step
Рет қаралды 182 М.
ХОТЯ БЫ КИНОДА 2 - официальный фильм
1:35:34
ХОТЯ БЫ В КИНО
Рет қаралды 2,6 МЛН