Reputation: 31
I am using Gatling for load testing. When I am creating Customer profiles , Customer IDs will be generated. I am able to extract the customer ID and saving in to session variables.
But How to store these values in to a Text file.
please help me.
Upvotes: 2
Views: 9946
Reputation: 1618
In the example below I'm saving the extracted NumberIDs out of the SOAP response and then save them into the numbersIDs.csv file so that it can be fed into another Request.
//Variables to store the extracted values of the response
var numberIDs : Seq[String] = _
//Java Writer
val numberIDs_writer = {
val fos = new java.io.FileOutputStream("numbersIDs.csv")
new java.io.PrintWriter(fos,true)
}
val scn = scenario("basicSimulation")
.exec(http("Request_One")
.post("/services")
.body(StringBody(inputXMLpayLoad))
.headers(Request_One_Header)
.check(bodyString.saveAs("Request_Response")) //Save the response in a variable called Request_Response
.check((status.is(200)))
//Extract all numberIDs of the SOAP response
.check(regex("""<NumberId>([\d]+)</NumberId>""")
.findAll
.transform { string => numberIDs = string; string }
.saveAs("numberIDs")))
//Save variable numberIDs into the csv file
.foreach("${numberIDs}", "id") {
exec(session => {
numberIDs_writer.println(session("id").as[String])
session
})
}
Upvotes: 3
Reputation: 2905
Another possibility (not tested, but could work) is to use response transformer (call .transformResponse after .post). In the transformer body you would get a response object from which you can extract the generated ID and append it into a file, collection, etc.. Then just return the original response as the transformation result. This is however not a very nice solution from the design point of view, because your transformation has a side effect.
Upvotes: 1
Reputation: 675
Since 2.0.0-M1, infoExtractor hook takes a Session parameter: https://github.com/excilys/gatling/issues/1004
There's also a builtin that adds the Session content to simulation.log records when the request fails. https://github.com/excilys/gatling/commit/b7b6299c658d0aa1b88971208eb0c98a9808e37f
You can adapt this example if you just want to log with logback.
class MySimulation extends Simulation with Logging {
def logSessionOnFailure(status: RequestStatus, session: Session, request: Request, response: ExtendedResponse): List[String] = {
if (status == KO) logger.error(session)
Nil
}
val httpConf = http
...
.extraInfoExtractor(logSessionOnFailure)
...
}
Upvotes: 1
Reputation: 7038
There's several ways to achieve that.
If you're familiar with Scala, you can:
If this is too complex for you, the most simple way is to use logback:
Regarding the second solution, check the logback documentation: http://logback.qos.ch/documentation.html
Upvotes: 4