Author Topic: Gatling / Scala builder pattern question for ScenarioBuilder and ActionBuilder  (Read 366 times)

Offline mbordelon

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
    • View Profile
Gatling and scala newbie here, done plenty of searching and looked at the documentation and posted in the gatling forum already, but i need a gentle nudge about builder patterns and abstract/traits to get me going:

I'd have a file (a formatted wiremock journal) that i'd like to use to create a gating scenario on the fly. The file several lines like this:

  {  "when": "21:21:09", "url": "/ssows/SSOws", "in": "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><ns5:getToken xmlns:ns2=\"java:language_builtins.lang\" xmlns:ns3=\"java:com.tl.ssows.parameters\" xmlns:ns4=\"java:com.tl.ssows\" xmlns:ns5=\"http://ws.thomsonlearning.com:80/ssows\"><ns3:password>xy</ns3:password><ns3:uid>app_cengage_sso</ns3:uid></ns5:getToken></soap:Body></soap:Envelope>", "out": "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><ns5:getTokenResponse xmlns:ns2=\"java:com.tl.ssows\" xmlns:ns3=\"java:language_builtins.lang\" xmlns:ns4=\"java:com.tl.ssows.parameters\" xmlns:ns5=\"http://ws.thomsonlearning.com:80/ssows\"><ns2:branchDesignator>0</ns2:branchDesignator>...<ns2:uid>app_cengage_sso</ns2:uid></ns5:getTokenResponse></soap:Body></soap:Envelope>"  }

From this is I have all the elements to create, line per line ( a counter would increment for each line in a loop ),

    .exec( http("step 0 = getToken(app_cengage_sso,xy)").post("/ssows/SSOws").body(StringBody("""<soap:Envelope xmlns... /soap:Envelope>""")).check(xpath("//ns4:token", List("ns4" -> "java:com.tl.ssows")).saveAs("admintoken0")).check(xpath("//ns2:uid", List("ns2" -> "java:java:language_builtins.lang")).saveAs("uid0"))   )

I know I would be instatiating a scenariobuilder and an actionbuilder to do this work, but both are abstract classes and I cannot work with them the way I am used to in java (scala is new to me). I have noticed someone trying to do something similar in a foreach loop. Is this the better approach? How to have the outer loop read from a text file?

 val scn = scenario("Test")
    .exec(session => {
      foreach(xs, "x") {

        val x = session("x").as[Integer]
        System.out.println(x)
        exec(http("post")
          .post("/blah/")
          .body(StringBody(x.toString))
          .check(status.is(200)))
      }
      Success(session)
    })

Thanks,

Offline jorge.s

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
    • View Profile
Dear mbordelon,

It seems to me that you posted your question in the wrong Scala Forum ... This is the Scala Infochannel (digital signage platform) one...