4

Starting with Gatling using Maven

 2 years ago
source link: https://blog.knoldus.com/starting-with-gatling-using-maven/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Reading Time: 4 minutes

Gatling is an open source load testing application, which uses Scala scripting language. Unlike Apache JMeter, Gatling doesn’t have a GUI interface. So, when you want to simulate a given scenario, you do it by writing a Scala script.

Here we will learn how to write Gatling script using Maven and also, understand the basic architecture of the script by using test scenario.

Prerequisites:

  • Maven should be downloaded and path should be set on the env variable.
  • Scala Plugin should be installed and integrated with IDE.

To setup Maven we have to follow below step:

  1. Click on New Project (File >> New Project)
  2. Select Maven ,Check on create from archetype and click on Add archetype optionjNthmluRWMjUl_mnDSAMDxeCzOPE9I6V9He06iCLeYHmSJSJgV0gwRUHjZT0drSE2uKWznda40ZDDm4SaBRvhnmn3gKefx2qy2a7KjmwpIcqyj3ieN5lDGFe1nn7IhiiUy5by6vB
  1. Enter GroupId, ArtifactId and Version on prompted window (you can find these detail in the link https://mvnrepository.com/artifact/io.gatling.highcharts/gatling-highcharts-maven-archetype) , Now click on Ok and Next
  1. Now give user friendly Name and ArtifactId and GroupId and click on Next and Finish.
  • groupId – by this Id your project will be uniquely identify across all the projects. Ex- com.gatling-practice
  • artifactId – this will be unique name of the project.
  1. Now Setup sdk for that Open Engine file (src >> scala >> Engine.scala) and click on Setup sdk

6. The pom.xml will create automatically and looks like :

  1. Now Create a simulations folder under scala folder and add scala file.p

Now you are good to start writing your script 

Simulation Architecture:

Gatling script consist of four section :

  • The HTTP protocol configuration
  • The headers definition  
  • The scenario definition
  • The simulation definition

HTTP protocol configuration

In this section we will provide information about our request for

  • baseUrl 
  • Common Headers, which will be added on each request

The HTTP Configuration is stored as a Scala value so that we can set it later in the simulation definition.

Headers definition

This section comes in picture when we have to define separate headers for each scenario. If we have common headers for all the scenarios then we usually do not use this section in our script.

Scenario definition

In this section we can define according to the requirement/use cases by providing a user friendly name and we can define several scenarios in a single script.

Scenario use two methods: exec and pause

  • The exec method is used to execute an action. Actions are usually requests that will be sent during the simulation
  • The pause method is used to simulate the think time of the user between consecutive requests.

Simulation definition

Here we are defining simulation like how many user can put the load on the server with the help of setup we can inject load in server by passing users in atOnceUsers method.

Configuring the Gatling Script:

Below Script code snippet is in Scala Programming Language

Rj4znMToX83d9dVzNG_yuOARme-Gs0wxX91xQDak2iPbbStw5kwXNPiAMGcs7IrKRrY_gQ2Fv1f0MpMjJqzXK4EX8G1XPwKDZZS1vKmOASmjJYtJ7zW-phiPd3q0ryl50suak-Pl

Script Execution:

We can execute script by two way:

  1. Through IDE – (Right click on Engine and click on Run “Engine”)
  1. Second way to execute script is through maven command from Terminal,

To execute command from terminal first you need to navigate to the Project directory after that run below command

mvn gatling:test

Note– to execute script using test field this you need to provide test(or any user friendly name) in scope tag of POM.xml. Kindly refer the screenshot present in step 6.

Gatling Report:

To view report either copy and paste the report path on browser which is appearing on the terminal or you can navigate to the project directory inside directory you will find these folder >>target>>gatling>>demoscript there you will find index.html click on thatiLijKBDxCRJB0p73JUZvK8zTQDcd5JiOZshYFkodF92RehxgfNL5s4IF0jpy01Phc-yBhzAdIcn2tD1mMyeTWSXiC79VplUoGp6KvPzXVqwBK-2UD1kIMKaQQ8z-TajTyp4_V075

5ElFasYmzDV_EbVrqviwzgAp-72tussjFUhpJv76WCkxpPOXSMG9S1GTHtKms9uN7k-yv-IyUPV8rovfsP-kVfaHmxOzX4AtidQy6ULsk5E6Tdg_WiA0vdu2iOhew_Kl3_P49kxA

UX22zMph00eoByraijQLL5QKtEJKqNHrmi_-cfck3Hcr18uZttdP6BNB_iGMIJtyEQwmoclQPMjNFLTk88RfKQ36wPa6WG26_06bm75KksmFa0AMF7N5Z4ecRwlAX5UzHOikRwfO

DWpq99eMPC-B0Hn4iwlJrlovyhsRPL8J-Dtftm2JqtEE2tWZQI3K5PF_ygSqzW4Sm_4qJVmbR56pN5MTloeLTCBqfQaKgWnYcM_QdkqGzeTtbAKNjqz7w6cQcPnqySic0-5o1DBG

Reference link:

https://gatling.io/docs/current/extensions/maven_plugin/#maven-plugin

For more blogs please visit to site

bbBkty2bYxEMNufPqnLsuJXTXtL_Kj8nSVFA8bRYF2OV5wCD3nakP52fg33jGbIkJjQ-dZvAb_w9PbJFqo8mRUPNUzE3U2ujrE2tm3VIkbXPGDsLrt3jsFpAh2YDe7E0qDvvjtCH


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK