简体   繁体   中英

Generate Gatling requests from dynamic data

I need to iterate over dynamically-generated application data, and don't see any detailed examples in the Gatling documentation. I'm using a feeder for predictable variables, but how do should I derive requests from dynamic? I've tried using Checks but I'm not sure if this is the correct approach. And how then do I iterate over the captured data and generate new get() requests?

For example:

val userLinks = exec(
    http("Follow Links")
    .get("/userLinks/")
    .headers(...)
    .check(
        regex("""__doPostBack('ct100$PageContent$FollowMe','(.*)')""")
        .ofType[(String)].findAll.optional.saveAs("FollowMeOptions")
    )
)

Is the above the correct approach? How do I use the results ("FollowMeOptions") if it is? I feel like this is a basic scenario that should be -- and likely is -- covered in the documentation, but I haven't had luck finding a concrete example there (or here on stack).

Thanks!

I think I've found the correct method and syntax. Note regex escapes:

val userLinks = exec(
    http("Follow Links")
    .get("/userLinks/")
    .headers(...)
    .check(
        regex("""__doPostBack\('ct100\$PageContent\$FollowMe','(.*)'\)""")
        .ofType[(String)].findAll.optional.saveAs("FollowMeOptions")
    )
).foreach("${FollowMeOptions}", "option") {
    exec(http("request option").get("/path/to/$option").headers(...)
}

Here is my answer to this: Problem Statement: I had to repeat the gatling execution for configured set of times, and my step name has to be dynamic.

object UrlVerifier {

  val count = new java.util.concurrent.atomic.AtomicInteger(0)
  val baseUrl = Params.applicationBaseUrl

  val accessUrl = repeat(Params.noOfPagesToBeVisited,"index") {
    exec(session=> {
      val randomUrls: List[String] = UrlFeeder.getUrlsToBeTested()
      session.set("index", count.getAndIncrement).set("pageToTest", randomUrls(session("index").as[Int]))
    }
    ).
    exec(http("Accessing Page ${pageToTest}")
      .get(baseUrl+"${pageToTest}")
      .check(status.is(200))).pause(Params.timeToPauseInSeconds)
  }

So basically UrlFeeder give me list of String (urls to be tested) and in the exec, we are using count (AtomicInteger), and using this we are populating a variable named 'index' whose value will start from 0 and will be getAndIncremented in each iteration. This 'index' variable is the one which will be used within repeat() loop as we are specifying the name of counterVariable to be used as 'index'

Also check, I am defining dynamic name of the http request ,like Accessing Page 'xyz'. This helps me understanding the reports in better way, like which exact url failed.

Hope it helps others as well.

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