Gatling Integration with Play


I have started working on a project which require stress testing using Gatling. I Setup the sbt project on which gatling is working fine. But when I try to integrate it using play framework, it doesn’t work. The project structure for both are different so it doesn’t work for both the project in the same manner.

Your build.sbt should be  like this:

import _root_.io.gatling.sbt.GatlingPlugin
import _root_.sbt.Keys._


name := """play-gatling-tutorial-one"""

version := "1.0-SNAPSHOT"


lazy val root = (project in file("."))
  .enablePlugins(PlayScala)
  .enablePlugins(GatlingPlugin)
  .configs(GTest)
  .settings(inConfig(GTest)(Defaults.testSettings): _*)


scalaVersion := "2.11.8"

libraryDependencies ++= Seq(
  jdbc,
  cache,
  ws,
  "org.scalatestplus.play" %% "scalatestplus-play" % "1.5.1" % Test,
  "io.gatling.highcharts" % "gatling-charts-highcharts" % "2.2.2" % "test",
  "io.gatling" % "gatling-test-framework" % "2.2.2" % "test"

)

resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"

lazy val GTest = config("gatling") extend (Test)

scalaSource in GTest := baseDirectory.value / "/gatling/simulation"
/*In this line we are just configuring to take all the gatling test cases 
from the "gatling/simulation" folder of the base directory.*/

and plugins.sbt should be like this:

//gatling plugin++++
addSbtPlugin("io.gatling" % "gatling-sbt" % "2.2.0")

// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.4")

// web plugins

addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.1.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.3")

addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.7")

addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.0")

addSbtPlugin("org.irundaia.sbt" % "sbt-sassify" % "1.4.2")

You need to create a folder in your base directory eg. gatling, and make conf and simulation folder in that directory. In conf folder put  your gatling configuration file and in simulation folder put all your gatling test scenarios.

Your folder structure should be like this:

app                       Application sources
build.sbt                 Application build script
conf                      Configurations files
  application.conf       Main configuration file
  routes                 Routes definition
gatling
 conf
     gatling.conf         Configuration file of gatling
 simulation              Put all your gatling test in this folder
 GatlingTest 
public  Public assets 
project  sbt configuration files 
 build.properties  Marker for sbt project 
 plugins.sbt  sbt plugins including play declaration
test 

To run the gatling test case you need to run activator

then ,

gatling: test to run all the test cases.command_line.png

Your result would look line this:

gatling_report.png

Gatling Report on browser would be like this:

/home/sid/Desktop/play-gatling-tutorial-one/target/gatling/gatlingtest-1470402193130/index.html

Index.html.png

To clone the Project visit on my Github Gatling with play

 

 

 

Advertisements
This entry was posted in gatling, Integration testing in play framework, LoadTesting, Performance Testing, Play 2.4.X, Play Framework, Scala, testing and tagged , , , , , , , , , , , , . Bookmark the permalink.

2 Responses to Gatling Integration with Play

  1. R van Duijn says:

    Thank you for the post. Any ideas on how to add this gatling report into sonarqube?

  2. rjvduijn says:

    Hi, thanks for the post! This was a huge help for me.
    Any ideas on how to publish the gatling report into sonarqube?

    I’ve done some digging on the web and found that using jacoco:check and jacoco-it:test should do the trick with the jacoco4sbt plugin.
    But as jacoco-it:test runs it:test underwater it does not execute gatling-it:test and thus has no reports to build.
    Hope you or anybody reading this has some pointers.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s