Scope of .exec and variables passed between the scopes

I have this (partly simulation):

`

.exec(
http(“getCardList”)
.get("/card/all")
.header(“X-Token”, “my_token”)
.check(status.is(200))
.check(jsonPath("$.resultCode").is(“SUCCESS”))
.check(jsonPath("$.membershipCard[0].card[0].offerId").saveAs(“offerId”)))
.exec(session2 => {
println((session2(“offerId”).as[String]))
session2
})

.exec(
http(“activateCard”)
.post("/card/activate")
.header(“X-Token”, “my_token”)
.body(StringBody("""{“offerId”: “${offerId}”, “membershipId”: “1361300168”, “osName”: “Android”, “osVersion”: “4.4”}""")).asJSON
//.body(ELFileBody(“activateCard.json”)).asJSON
.check(status.is(200))
.check(jsonPath("$.resultCode").is(“SUCCESS”)))

`

In the last .exec I am trying to use the variable saved in the first .exec without any luck.
It fails. But when ‘hard-coding’ the variable into the StringBody it works. I have verified that ‘offerId’ is captured using my reggae and print.

Is it possible to pass one variable (offerId) from one .exec to the next?

I am actually using ELFileBody and a request body with the parameter ‘offerId’ but that did not work either, so I am using StringBody to ‘debug’.

Please advice,

Magnus

My guess is the first “offerId” in request body is evaluated as the value of offerId and not the name as you intend it to.

Try changing the name to something like myOfferId

`
.check(jsonPath("$.membershipCard[0].card[0].offerId").saveAs("myOfferId"))...

.body(StringBody("""{"offerId": "${myOfferId}"......
`

thanx :slight_smile:

What you are doing should work. Beware of typos. Because it uses strings, a mis-typed letter can make it not work, even though it compiles. That’s why I started using constants.

Yes, typo it was…