How to print response on console????

13,259 views
Skip to first unread message

47sai...@gmail.com

unread,
Nov 12, 2014, 12:48:04 AM11/12/14
to gat...@googlegroups.com
Hi,

   I am new to gatling....How to print response for each request on console...And how can I take some value from response and store into variable...And In other request I want to use that variable...I tried with saveAs method...but it doesn't work for me..and I am unable to print the value on console....How to do this???can any one please explain with perfect example code....



Thanks

John Arrowwood

unread,
Nov 12, 2014, 12:49:09 PM11/12/14
to gat...@googlegroups.com
Here is the pattern I typically follow, though I have made some DSL of my own to make it more compact:

exec(
  http
( "Some Restful Service" )
   
.get( pathToService )
   
.check( jsonPath( "$" ).saveAs( "RESPONSE_DATA" ) )
 
)
.exec( session => {
  println
( "Some Restful Service:" )
  println
( session( "RESPONSE_DATA" ).as[String] )
  session
})

If you are doing something other than a JSON web service, you might alter the .check call to be something more like:

.check( bodyString.saveAs( "RESPONSE_DATA" ) )

If you are just starting out, there is a lot to learn about Gatling.  There is no way around it, you are going to have to learn the core principles.  Start by reading the documentation: http://gatling.io/docs/2.0.2/

Suganthi Thangavel

unread,
Mar 8, 2017, 1:59:15 AM3/8/17
to Gatling User Group
Awesome , this saved my time.

Suganthi Thangavel

unread,
Mar 8, 2017, 3:09:17 AM3/8/17
to Gatling User Group
I have on one question ,

After extracting from json , How will I add it it to map, I have tried the following code,

       var res:Map[String,String] = Map()
       val res_all = res + ("key1" -> ${extracted}) 
       print ("Map res_al:" + res_all)

This says ${extracted} not found

Siegfried Goeschl

unread,
Mar 8, 2017, 3:10:49 PM3/8/17
to Gatling User Group
Assuming that you wand to see the response for ALL of your requests you can also change the logger configuration

mvn -Dlogback.configurationFile=conf/logback-debug.xml -Dgatling.simulationClass=XXX gatling:test


whereas my "logback-debug.xml" looks like this


<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
<immediateFlush>true</immediateFlush>
</encoder>
</appender>

<root level="DEBUG">
<appender-ref ref="CONSOLE" />
</root>

</configuration>

Reply all
Reply to author
Forward
0 new messages