Plugins are used in software for adding new functionalities inside the program definition. Plugins are helpful for adding extra functionalities inside the software without making it a heavier one.
There are different types of plugins available for Gatling. Some are official and some are third-party plugins. So, without wasting more time, let us move to Plug-ins of Gatling.
The official plugins of Gatling are as follows:
The SBT Plugin integrates Gatling with SBT and allows us to use Gatling as a testing framework also. There are several steps involved in configuring the SBT to integrate with the Gatling.
While Setting up, we need to add the following code into the folder Project/plugins.sbt.
addSbtPlugin("io.gatling" % "gatling-sbt" % "2.2.2")
This is to keep in mind that, the following dependencies must be added before proceeding further.
"io.gatling.highcharts" % "gatling-charts-highcharts" % "2.3.0" % "test"
"io.gatling"% "gatling-test-framework" % "2.3.0" % "test"
After that in the .scala bulid, the following code has to be added.
import io.gatling.sbt.GatlingPlugin
lazy val project = Project(...)
.enablePlugins(GatlingPlugin)
.settings(libraryDependencies ++= /* Gatling dependencies */)
For the SBT 0.13.6 or the later versions in your .SBT file, add the code below.
enablePlugins(GatlingPlugin)
libraryDependencies ++= /* Gatling dependencies */
With the SBT testing framework, we are able to run Gatling simulations using SBT standard test, testOnly, testQuick, and many other tasks.
The SBT Plugin introduces many customizations and it should be kept in mind that it is not interfering with any unit tests, so the commands are integrated to custom configurations, requiring us to prefix them with Gatling or Gatling-it, eg. gatling:test or gatling-it:test.
The SBT plugin provides two different SBT configurations, they are Gatling and GatlingIt. They are assigned to different source directories so that it becomes possible to separate our simulations according to our needs.
Basically, two things must be taken care of:
Let us now see the default settings. For the Gatling Configuration:
For the GatlingIT Settings.
If any case the default settings are overridden somehow, we need to reset those settings on the project, in the way:
scalaSource in Gatling := sourceDirectory.value / "gatling" / "scala"
lazy val root = (project in file(".")).settings(inConfig(Gatling)(Defaults.testSettings): _*)
Below we will see the additional tasks which are performed by the Plugin:
This Plugin can be launched while building our projects. To set up the Gatling-Maven, the following dependencies should be added.
<dependencies>
<dependency>
<groupId>io.gatling.highcharts</groupId>
<artifactId>gatling-charts-highcharts</artifactId>
<version>X.Y.Z</version>
<scope>test</scope>
</dependency>
</dependencies>
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>X.Y.Z</version>
</plugin>
This below configuration can be used, but this is optional.
<configuration>
<configFolder>${project.basedir}/src/test/resources</configFolder>
<dataFolder>${project.basedir}/src/test/resources/data</dataFolder>
<resultsFolder>${project.basedir}/target/gatling/results</resultsFolder>
<bodiesFolder>${project.basedir}/src/test/resources/bodies</bodiesFolder>
<simulationsFolder>${project.basedir}/src/test/scala</simulationsFolder>
<runDescription>This-is-the-run-description</runDescription>
<!-- <noReports>false</noReports> -->
<!-- <reportsOnly>directoryName</reportsOnly> -->
<!-- <simulationClass>foo.Bar</simulationClass> -->
<!-- <jvmArgs> -->
<!-- <jvmArg>-DmyExtraParam=foo</jvmArg> -->
<!-- </jvmArgs> -->
<!-- <fork>true</fork> -->
<!-- <propagateSystemProperties>true</propagateSystemProperties> -->
<!-- <failOnError>true</failOnError> -->
</configuration>
The Gatling Maven Plugin can be directly launched with the test or the integration-test task.
mvn gatling:test
mvn gatling:integration-test
The next task is to configure the execution block. This below code can be used to configure the execution block.
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>${gatling.version}</version>
<!--This is optional, if you are having only one simulation-->
<configuration>
<simulationClass>Foo</simulationClass>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
After the configuration of the execution block, we may choose to run the plugin several times in a build, in order to to run several simulations simultaneously. The other way is to configure several execution block each with having a different configuration block.
It has to be kept in mind, that those won't be kept while running gatling:test, as the execution would be initiated by Maven's Cycle.
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>${gatling.version}</version>
<executions>
<execution>
<id>execution1</id>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<simulationClass>Foo</simulationClass>
</configuration>
</execution>
<execution>
<id>execution2</id>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<simulationClass>Bar</simulationClass>
</configuration>
</execution>
</executions>
</plugin>
I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.