scalagatlingscala-gatlinggatling-plugin

Create Bulk XML from template for POST request using gatling/scala


I want to send bulk xml to my soap request body. I want to know is there any way to generate them dynamically through Gatling/Scala This is how I am doing

private val request=exec( http("Post request to create") .post("/endPoint") .headers(Utils.soapHeaders) .body(ElFileBody("requestbody/ids.xml")) .check(status.is(Utils.successStatus)) )

private val feedId = Iterator.continually( Map( "id" -> Random.alphanumeric.take(13).mkString, "transactionId" -> Random.alphanumeric.take(14).mkString ) )

val scnPostVehicleAsn=Utils.createScenario("soapService", feedId, request)

and requestbody/ids.xml has the template with dynamic values ${transactionId} & ${id}.

So Is there any way to dynamically generate xml based on the template, I am not looking for repeat functionality. Just generate xml once before execution and pass it and later I will make rest calls to validate them


Solution

  • I figured it out myself. I have created a list of random number and passed it to xml directly

    val randomNumbers = List.fill(number)(prefix.concat(Random.alphanumeric.take(13).mkString)) { randomNumbers.map( i => i }

    Then,

    val file = new File(System.getProperty("user.dir") +"/performance-tests/src/test/resources/requestBody/ids.xml") val bw = new BufferedWriter(new FileWriter(file)) bw.write(VehicleAsns.toString()) bw.close()