# Attribute issue

**URL:** <https://community.gatling.io/t/attribute-issue/2348>\
**Category:** Gatling (Open-Source)\
**Created:** [June 9, 2015, 9:01pm UTC](https://community.gatling.io/t/attribute-issue/2348 "2015-06-09T21:01:55Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![praveen](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@praveen](https://community.gatling.io/u/praveen)\
**Post date:** [June 9, 2015, 9:01pm UTC](https://community.gatling.io/t/attribute-issue/2348/1 "2015-06-09T21:01:55Z")

</div>

Hi folks. I’m new to Gatling and to Scala and trying to execute some scenarios. I have got an issue with my scenario when I try to use “token” in my request body - No attribute named ‘token’ is defined"

can any one figure out what is wrong or what is missing to define?  
.exec(session =\> session.set(“token”, token)) =\>Tried to use this expression but still gives me error “Value token: not found”

val scn = scenario(“scenario name”)  
.exec(http(“get\_token”)  
.post("/oauth/token")  
.body(StringBody("""{“grant\_type”: “pass”, “client\_id”: “12345678990”, “client\_secret”: “secretkey”, “username”: “xxcdcd”, “password”: “xxx”, “scope”: “”}""")).asJSON  
.check(status.is(200))  
.check(jsonPath(".access\_token").find.saveAs(“token”))

)  
.pause(1)  
.exec(http(“get\_Authorization”)  
.post("/profile")  
.body(StringBody("""{“access\_token”: “${token}”, “application-key”: “33bdndfnnfnrnt556677”}""")).asJSON  
.check(status.is(200))  
.check(jsonPath(".Authorization\_token").find.saveAs(“Authorization”))  
)  
.pause(2)  
.exec(http(“Get\_locations”)  
.get("/api/locations?application-key=33ede4567890123e4e4")  
.header(“Authorization”, “${token}”)  
.check(status.is(200))

---

<div class="post-metadata">

**Author:** ![Andrew\_Krischer](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@Andrew\_Krischer](https://community.gatling.io/u/Andrew_Krischer)\
**Post date:** [June 10, 2015, 2:20pm UTC](https://community.gatling.io/t/attribute-issue/2348/2 "2015-06-10T14:20:53Z")

</div>

**.check(jsonPath(".access\_token").find.saveAs(“token”))**

The root element of a jsonPath is “$”

Try **.check(jsonPath("$.access\_token").find.saveAs(“token”))**

And I’d update all your other jsonPaths as well.

---

<div class="post-metadata">

**Author:** ![praveen](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@praveen](https://community.gatling.io/u/praveen)\
**Post date:** [June 10, 2015, 3:19pm UTC](https://community.gatling.io/t/attribute-issue/2348/3 "2015-06-10T15:19:52Z")

</div>

Hi,  
Tried using the root element in all the jsonPath (**.check(jsonPath("$.access\_token").find.saveAs(“token”)))** but still getting the same issue. The following are the headers used in the code. Is there any issue with headers?

package computerdatabase

import io.gatling.core.Predef.\_  
import io.gatling.http.Predef.\_  
import scala.concurrent.duration.\_

class BasicSimulationAll extends Simulation {

val httpConf = http  
.baseURLs(“URL1” , “URL2”)

.acceptHeader(“text/html,application/xhtml+xml,application/xml;q=0.9,_/_;q=0.8”)  
.doNotTrackHeader(“1”)  
.acceptLanguageHeader(“en-US,en;q=0.5”)  
.acceptEncodingHeader(“gzip, deflate”)  
.userAgentHeader(“Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0”)

val headers\_10 = Map(“Content-Type” → “”“application/x-www-form-urlencoded”"")  
val headers\_9 = Map(“Content-Type” → “”“application/json”"")  
val headers\_8 = Map(“access\_token” → “”“token”"")

---

<div class="post-metadata">

**Author:** ![Andrew\_Krischer](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@Andrew\_Krischer](https://community.gatling.io/u/Andrew_Krischer)\
**Post date:** [June 10, 2015, 3:37pm UTC](https://community.gatling.io/t/attribute-issue/2348/4 "2015-06-10T15:37:54Z")

</div>

Hm, I don’t think this would cause the problem but you don’t need the **find** in your check.

Try adding this after your first exec block that executes the request:

**.exec(session =\> {**  
**println(session(“token”).asOption[String])**  
**session**  
**})**  
**…**

that will print **Some(xyz)** or **None** based on if the token is actually saved in the session or not. I’d expect the check to fail if it didn’t actually find any token, since it implicitly calls **exists**.

---

<div class="post-metadata">

**Author:** ![praveen](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@praveen](https://community.gatling.io/u/praveen)\
**Post date:** [June 10, 2015, 4:09pm UTC](https://community.gatling.io/t/attribute-issue/2348/5 "2015-06-10T16:09:37Z")

</div>

As per suggestion, Removed **find** in my check and added the below **.exec** function after the first exec block but still the same. Attachment is the error screenshot please check.

![Attribute error.PNG](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/1X/0469fee657bf5066ea807df2d0cbe277a646ae96.png)

---

<div class="post-metadata">

**Author:** ![Andrew\_Krischer](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@Andrew\_Krischer](https://community.gatling.io/u/Andrew_Krischer)\
**Post date:** [June 10, 2015, 4:53pm UTC](https://community.gatling.io/t/attribute-issue/2348/6 "2015-06-10T16:53:23Z")

</div>

That doesn’t show the console output I mentioned. What does

**.exec(session =\> {**  
**println(session(“token”).asOption[String])**  
**session**  
**})**

produce?

---

<div class="post-metadata">

**Author:** ![praveen](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@praveen](https://community.gatling.io/u/praveen)\
**Post date:** [June 10, 2015, 6:04pm UTC](https://community.gatling.io/t/attribute-issue/2348/7 "2015-06-10T18:04:05Z")

</div>

Out put of the below execution result shows **found nothing.** screenshot attached

**.exec(session =\> {**  
**println(session(“token”).asOption[String])**  
**session**  
**})**

 ![result produce nothing.PNG](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/1X/a80134c5edf3f6a77e64324119cce701e348272b.png)

---

<div class="post-metadata">

**Author:** ![Andrew\_Krischer](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@Andrew\_Krischer](https://community.gatling.io/u/Andrew_Krischer)\
**Post date:** [June 10, 2015, 6:49pm UTC](https://community.gatling.io/t/attribute-issue/2348/8 "2015-06-10T18:49:55Z")

</div>

What you’re posting is inconsistent.

The **found nothing** error is what happens if the response does not contain anything at the specified path. Your previous post doesn’t seem to indicate that.

**.exec(session =\> {**  
**println(session(“token”).asOption[String])**  
**session**  
**})**

does not actually affect the request/response at all, it is simply a debug statement which will print whatever is stored as “token” in the session. If you get that **found nothing** error, that means there’s no token to save in the response.

---

<div class="post-metadata">

**Author:** ![praveen](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@praveen](https://community.gatling.io/u/praveen)\
**Post date:** [June 11, 2015, 3:52pm UTC](https://community.gatling.io/t/attribute-issue/2348/9 "2015-06-11T15:52:49Z")

</div>

Hi Andrew,

I think I got to fix first this first. In actual am not able to print the token. When executing the below simple code for receiving the token get the error "**jsonPath($.token).find(0).exists, found nothing".**  
is there something from the request point am missing to declare and get the token in response?

val scn = scenario(“Bearer token”)  
.exec(http(“request\_1”)  
.post("/oauth/token")  
.body(StringBody("""{ “grant\_type”: “password”, “client\_id”: “client1xxxxxxx”, “client\_secret”: “13cxxxxx”, “username”: “user”, “password”: “xxxx”, “scope”: “”}""")).asJSON  
.check(jsonPath("$.access\_token").saveAs(“token”))  
)  
.exec(session =\> {  
println(session(“token”).asOption[String])  
session  
})

---

<div class="post-metadata">

**Author:** ![Abhinav\_Gogna](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Abhinav\_Gogna](https://community.gatling.io/u/Abhinav_Gogna)\
**Post date:** [June 13, 2015, 6:57am UTC](https://community.gatling.io/t/attribute-issue/2348/10 "2015-06-13T06:57:11Z")

</div>

It sounds like your JsonPath is not extracting right results. Why not test your json repsonse and json path to remove that possibility

[http://jsonpath.curiousconcept.com/](http://jsonpath.curiousconcept.com/) - choose steffan goesener implementation.

---

<div class="post-metadata">

**Author:** ![praveen](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@praveen](https://community.gatling.io/u/praveen)\
**Post date:** [June 15, 2015, 7:36pm UTC](https://community.gatling.io/t/attribute-issue/2348/11 "2015-06-15T19:36:25Z")

</div>

My Json response seems to be fine, As requested tried with goesener implementation by adding Json data and Json path expression ($.access\_token) then processing it, got the access\_token out put result.  
I have just added the header ( .header(“access\_token”, “${token}”) ) to my code then i dont see the error ( "**jsonPath($.token).find(0).exists, found nothing" ) but** still experiencing the issue with **“No Attribute named token is defined”.** From code point i dont see that anything is missed\*\*. Do we have to define token as val?\*\*

---

<div class="post-metadata">

**Author:** ![Abhinav\_Gogna](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Abhinav\_Gogna](https://community.gatling.io/u/Abhinav_Gogna)\
**Post date:** [June 16, 2015, 11:47am UTC](https://community.gatling.io/t/attribute-issue/2348/12 "2015-06-16T11:47:08Z")

</div>

Please share your simultation and JSON response. Otherwise it’s all a guess work.
