Karate framework variable usage

生来就可爱ヽ(ⅴ<●) 提交于 2020-03-03 07:40:48

问题


I have this steps:

...
Then status 200
And match response.requests[0].request.url == "/endpoint"
And json body = response.requests[0].request.body
And match body == { "something": "something"}

To simplify, I tried to put response.requests[0].request in a variable called request:

...
Then status 200
And def request = response.requests[0].request
And match request.url == "/endpoint"
And json body = request.body
And match body == { "something": "something"}

I'm having the following error:

'request' is not a variable, use the form '* request <expression>' instead

I read the documentation and the use of request seems to be fine:

Given def color = 'red '
And def num = 5
Then assert color + num == 'red 5'

What am I doing wrong?

Thanks in advance.


回答1:


Just make this change:

* def req = response.requests[0].request
# other steps
* request req

We simply disallow def request (using request as a variable name) because a lot of newbie users get confused. The error message has worked 99.9% of the time for users to understand what the problem is, but I guess you fall in the 0.1% :)



来源:https://stackoverflow.com/questions/60007947/karate-framework-variable-usage

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!