简体   繁体   中英

Gatling httpRequest with dynamic method from collection

I want to build a Gatling scenario from a collection of structured data (StructuredDataCollection).

My problem is, that I'm unable to pass in the "method" (as in HTTP method) from an element from the collection into the http call of the actual test.

Here's a code snippet.

  def testScenario(duration: Int) = scenario("SO").during(duration) {
    exec {
      session => {
        val test = StructuredDataCollection.next()
        val title = test.title
        val method = test.method // Not being used, because it does not work like that :(
        val endpoint = test.endpoint
        val requiredParameters = test.requiredParameters
        val code = test.code
        session
          .set("title", title)
          .set("methodFUG", method).set("endpoint", endpoint)
          .set("requiredParameters", requiredParameters)
          .set("code", code)
      }
    }
    .exec(
      http("${title}")
        .httpRequest("get", "${endpoint}") // TODO: method can't be passed in as an expression.
        .queryParamMap("${requiredParameters}")
        .check(status.is("${code}"))
    )
  }

As you can see, I've hard-coded "get", but I'll need that to be replaced with the actual value from the method property from the current selected item from the collection.

Unfortunately, Gatling's DSL isn't available in all the places where you'd expect it to be, and it's just reading that as a string.

It took me some time to realize, that http("${title}").httpRequest("${methodFUG}", "${endpoint}") will actually make a HTTP call with the invalid method "${methodFUG}" and not the value from the collection element, which could be "GET", "POST", "PUT", "DELETE", and so on.

httpRequest signature is (method: String, url: Expression[String]) , see documentation .

It cannot take an Expression, only a static String.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM