In one of our project we needed to test a node.js application, so in this blog, I’ll be discussing node.js application using Gatlingjs.
Gatlingjs
Gatlingjs is an npm library to run gatling from a node.js project by placing the simulation files in your project repository.
Prerequisites
In order to setup Gatling, your system should have JDK8 and Scala installed so following are the links to install them:
If you are using an IDE (i.e IntelliJ) you just need to install scala plugin.
Installation of gatlingjs
Execute following commands to install gatlingjs:
Sudo apt-get install npm
npm i gatlingjs -D
Configuration of Project Structure
To run simulations you have to configure your project library. Gatlingjs requires following directories where you keep your simulation files so that gatlingjs can identify the specific simulation to perform testing.
As you can see in the above picture, various directories are created which required by gatlingjs in the project root
-
test/performance/results
This directory contains the HTML representation of the report
-
test/performance/user-files/simulations
This directory contains the .scala files for the simulation
-
test/performance/user-files/data
This directory contains the data feeds
-
test/performance/user-files/bodies
This directory contains the things related to request body
Starting Gatlingjs simulation
To start the simulation you need to execute the following command
./node_modules/gatlingjs/dist/index.js
After executing the command in the terminal the testing simulation will start running
You can see in the above picture an example of running simulation.
After completing the simulation you can check the HTML report generated in the result directory or you can open the report in any browser by copying the path of the index.js file from the end of your simulation and directly paste it into your browser.
As you can see above pictures are example report generated.
Thanks!
References :
https://www.npmjs.com/package/gatlingjs
https://gatling.io/docs/current