I have this code for gatling where i wish to pass auth_token to soap request body. Soap request body is written in a txt file and that txt file is called in ElFilebody

All i need is to send access_token which is generated in saveAs("access_token") to be sent to ElFileBody("Soap_request_CancelEvent.txt")

Content of Soap_request_CancelEvent.txt is below
<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:ns="http://www.example.com/Service/2013-03">
<soapenv:Header/>
<soapenv:Body>
  <ns:CancelEvent>
     <!--Optional:-->
     <ns:request>
        <ns:AuthToken>${access_token}</ns:AuthToken>
        <ns:SanctionNumber>?</ns:SanctionNumber>
     </ns:request>
   </ns:CancelEvent>
 </soapenv:Body>
</soapenv:Envelope>

Error in Gatling console is

 Session(Test Cancel Event Soap Request,23,Map(caee65d1-d380-48e9-8566- 
 9d8efb16b5fa -> 0, 6014555f-5487-44bc-9384-864dece96fe0 -> 
 5),1557435685640,-125,KO,List(ExitOnCompleteLoopBlock(6014555f-5487-44bc- 
 9384-864dece96fe0), ExitOnCompleteLoopBlock(caee65d1-d380-48e9-8566-  
 6b5fa)),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$37 
 2/[email protected])
14:01:30.520 [ERROR] i.g.h.a.s.HttpRequestAction - 'httpRequest-17' failed 
to execute: No attribute named 'access_token' is defined

Code is below

 package simulations

import scala.io.Source

 class ERBSJson extends BaseSimulation  {


 val httpProtocol = http
 .baseURL("http://services.online.local:4059/Business/")

 val uri03 = "https://api.platform.com"



   )

 val header_cancel = Map(
 "POST" -> "http://services.online.local:4059/Business/ HTTP/1.1",
 "Accept-Encoding" -> "gzip,deflate",
 "Content-Type" -> "text/xml;charset=UTF-8",
 "SOAPAction" -> "http://www.example.org/Service/2013- 
 03/IEventReporterEndpoint/CancelEvent",
 "Content-Length" -> "429",
 "Host" -> "r20services.onlinegaming.local:4059",
 "Connection" -> "Keep-Alive",
 "User-Agent" -> "Apache-HttpClient/4.1.1 (java 1.5)"
 )

 val headers_10 = Map("Content-Type" -> "application/json","Authorization" 
 -> "${token_type} + ${access_token}" )



val source: String = Source.fromFile("C:/Gatling2/resources/data/input- 
ERBS.json").getLines.mkString
def userCount: Int  = JsonPath.parse(source).read("$.[0].user")
def testDuration: Int  = JsonPath.parse(source).read("$.[0].testDuration")
def rampDuration: Int  = JsonPath.parse(source).read("$.[0].rampDuration")



before {
  println(s"Running test with ${userCount} users")
  println(s"Ramping users over ${rampDuration} seconds")
   println(s"Total Test duration: ${testDuration} seconds")
  }


def CancelEvent()={
   repeat(990000000){


  exec(flushHttpCache)
  exec(flushHttpCache)
    .exec(http("Cancel Event")
      .post("EventReporterV2")
      .headers(header_cancel)
      .body(ElFileBody("Soap_request_CancelEvent.txt"))
      .check(status.in(200,201)))//checkforaspecificstatus
    .exec{session=>println(session);session}//parameterfortheorgIdgoeshere
    .pause(1)

    }
         }



 val scenario1 = scenario("Test Cancel Event Soap Request ")
 .exec(http("Event-Reservations-Web-Image-Login")
  .get("https://api.origin.cloud/dev/event-reservations- 
 /loading.dfbfd678.svg")
  .headers(headers_1)
  .resources(http("Http Header Token Authentication Url")
    .options(uri03 + "/auth/oauth/token")
    .headers(headers_7),
    http("Token Generation Url For Post")
      .post(uri03 + "/auth/oauth/token")
      .headers(headers_8)
      .formParam("grant_type", "password")
      .formParam("username", "[email protected]")
      .formParam("password", "fJC2RuVmHB")


  .basicAuth("ikrwugh3883gh","NbnEEqmDLSfno315o87ghFGYr3jybtzbi76sr")
      .check(jsonPath("$.access_token").exists.saveAs("access_token"))
      .check(jsonPath("$.token_type").exists.saveAs("token_type"))





  ))
.forever() { // add in the forever() method - users now loop forever

  exec(CancelEvent())
}




 setUp(

   scenario1.inject(
   nothingFor(5 seconds),
  rampUsers(userCount) over ( rampDuration ))
  .protocols(httpProtocol))


.maxDuration(testDuration)

}

1 Answers

0
James Warr On Best Solutions

can you try with removing the '.exists' command? It's not necessary if you're saving anyway