Gatling is an open source load testing tool used to test the web application running under HTTP protocol support. All HTTP protocol specific user request can be triggered by using the DSL (Domain Specific Language) from Scala and the response can be validated using different assertion/checks available in Gatling.
User request can be triggered to the web server using different simulation setup as follows; User injection to the webserver will be commenced with different approach based on your needs;
setUp(
scn.inject(
nothingFor(4 seconds), // 1
atOnceUsers(10), // 2
rampUsers(10) over (5 seconds), // 3
constantUsersPerSec(20) during (15 seconds), // 4
constantUsersPerSec(20) during (15 seconds) randomized, // 5
rampUsersPerSec(10) to 20 during (10 minutes), // 6
rampUsersPerSec(10) to 20 during (10 minutes) randomized, // 7
splitUsers(1000) into (rampUsers(10) over (10 seconds)) separatedBy (10 seconds), // 8
splitUsers(1000) into (rampUsers(10) over (10 seconds)) separatedBy atOnceUsers(30), // 9
heavisideUsers(1000) over (20 seconds) // 10
).protocols(httpConf)
)
Please refer the below URL for detailed information about the simulation setup;
https://gatling.io/docs/2.3/general/simulation_setup/
The advantage of Gatling is Asynchronous support in which virtual users request will be pushed to web server in a dedicated thread in the form of messages (non-blocking approach).
Gatling Concepts:
- Session represent the virtual users in which request has been triggered and store the data
- Feeders is a data driven model in which test data can be pushed to the session
- Checks is used to verify the response code from web server and it can be used to capture the elements, which will be re-use for subsequent request
- Assertions is used to define acceptance criteria
- Publish HTML reports
Pre-requisite: JDK 8 should be installed in your system in which downloaded Gatling folder is enough to kick-start the load test.
Let us see the basic steps to work on the Wikipedia login request in which 10 concurrent request I’m going to trigger using Gatling tool;
Play with the Browser
- Open the Firefox browser (I’ve used V61.0.2)
- Click ‘Open Menu’
- Click ‘Web Developer’ option
- Click ‘Network’ option (Ctrl + Shift + E)
- Ensure ‘Persist Logs’ option enabled in the Network Monitor
- Copy and paste the URL in the Address bar https://en.wikipedia.org/wiki/Main_Page
- You could see request/response in the Network Monitor
- Click ‘Log in’ link in the top right corner
- Enter the username and password of your Wikipedia account
- Click Login button and ensure Wikipedia home page displayed with your account
- Click ‘HAR’ option in the top right corner of Network Monitor window
- Click ‘Save All As HAR’ (Refer below screenshot) and save the file in your system
- Logout and close the browser window
Play with Gatling Recorder batch file
- Download the Gatling setup in zip format using the URL https://gatling.io/download/
- Unzip the file
- Go to ‘bin’ folder and run the ‘recorder.bat’ in the command prompt based on the below screenshot;
- Gatling ‘Recorder Configuration’ will automatically open
- Click ‘HAR Converter’ as ‘Recorder mode’ in the top right corner (By default ‘HTTP Proxy’ will be there)
- Click ‘Browse’ button associated with ‘HAR File:’ text box
- Enter the package name as ‘wikigatling’ in the ‘Package:’ textbox
- Leave all the options as default selection based on the below screenshot
- Click ‘Start’ button in bottom right of the recorder configuration window
- You could see the message ‘Success’ message of converting the HAR file to Gatling Simulation based on the below screenshot;
- Close the Recorder Configuration window.
- Ensure Gatling simulation in the name of ‘wikigatling’ has been created under the ‘user-files\simulations’ folder
Play with Gatling batch file – Trigger 10 virtual user request to web server
- Open the ‘RecordedSimulation.scala’ file under the folder ‘user-files\simulations\wikigatling’
- You could see all the user actions available in the file
- Wikipedia website URL is available under ‘baseURL’ of httpProtocol variable
- HTTP request header information has been captured
- Scenario has been created under the name val scn = scenario(“RecordedSimulation”)
- Get method has been used to fetch the information from web server
- Post method has been used to push the username and password to the webserver
- Each individual request is having its unique number Example: http(“request_42”)
- Refer the end of the file section in which you could see the setup method
- Setup method comprised of scenario injection stuff in which atOnceUsers(1) one user will be appended by default
- Change the number of users to 10 in which at once, 10 concurrent user requests will be triggered to the web server
- Save the scala file after change the virtual user data as 10;
setUp(scn.inject(atOnceUsers(10))).protocols(httpProtocol)
- Run ‘gatling.bat’ file in the command prompt under the bin folder
- Enter the simulation number of [11] ‘wikigatling.RecordedSimulation’ in the command prompt (Please note simulation number will vary for everyone)
- Press ‘Enter’ in keyboard by leaving simulation id as blank
- Press ‘Enter’ in keyboard by leaving run description as blank
- You could see Simulation started message with Requests information
- Load Test execution got completed and Test Report has been generated in the ‘results’ folder
- Open the ‘index.html’ file to visualize the detailed load testing report as follows;
- Response Time in ms – Min, 50th pct, 75th pct, 95th pct, 99th pct, Max, Min, Std Dev
- Error section
- Active Users Stats
- Response Time Distribution
- Response Time percentiles over time
- Number of requests per second
- Number of responses per second
I will be sharing the feeder (Test data management), checks and assertion usage in the forthcoming Gatling specific post.
Thank you!!!