0

Is it possible to save an attribute at runtime and then save it as another attribute? For instance, I have an ID that is used in the URL, I've captured it from one page, however there are a list of 5 on the page. I can use findAll to select them all, and then ${AttributeName.random()} to select one at random.

However how do I then go and save that as an attribute and then use it elsewhere? As it needs to be the same each time and if I run random again obviously it'll change string each time.

I could do an ${AttributeName(storedRandomNumber)} but the code could start to be a little messy and was wondering if there was something a little cleaner to use?

jknutt1568
  • 21
  • 5

1 Answers1

0

You could make another exec() right after this request to assign the random value you want with the session.set() method, this value then is saved for the entire thread to be reused.

EX :

val scenario = scenario("scenarioName")
.exec(
  http("<-- Name Of Request -->")
    .get("<LINK _TO_FIRST_REQ>")
    .check(jsonPath("$.items[*].id").findAll.optional.saveAs("ListOfAttributeNames"))
)
.exec( session => session.set("randomAttributeNameSelected", session("ListOfAttributeNames").as[Seq[String]]
  .apply(scala.util.Random
    .nextInt((session("ListOfAttributeNames").as[Seq[String]].size - 0) + 1)))
)
.exec(
  http("We use the ID here")
    .get(session => "http://domain.something.com/api/" + session("randomAttributeNameSelected").as[String])
)

Thus anytime in the same thread if you access session("randomAttributeNameSelected").as[String] it will give you random ID.

Gery
  • 555
  • 4
  • 6