如何在空手道框架中使用 - 获取值 json 例如:属性 auth-token

How to get value json with - in karate framework Ex: Attribute auth-token

帮助解决以下问题

变量:

* def token = loginResponse.response.data.attributes.auth-token

错误:

-unknown-:7 - javascript evaluation failed: loginResponse.response.data.attributes.auth-token, ReferenceError: "token" is not defined in at line number 1 com.intuit.karate.exception.KarateException: -unknown-:7 - javascript evaluation failed: loginResponse.response.data.attributes.auth-token, ReferenceError: "token" is not defined in at line number 1 at ✽.* def token = loginResponse.response.data.attributes.auth-token (-unknown-:7)

架构 json:

{
"data": {
    "id": "3326",
    "type": "users",
    "attributes": {
    "email": "emerson@gmail.com",
    "auth-token": "3ve6mPU4G-txLBmvc5eJ",
    "created-at": "2020-04-19T17:30:54.031Z",
    "updated-at": "2020-04-21T17:47:39.649Z"
    }
}
}

要求:

Scenario: List tasks

Given path '/tasks'

And header Accept = " application/vnd.tasksmanager.v2"

And header Authorization = token

When method GET

Then status 200

对于JSON键中的特殊字符,使用方括号访问:

* def token = loginResponse.response.data.attributes['auth-token']