【问题标题】:Karate framework variable usage空手道框架变量使用
【发布时间】:2020-01-31 16:41:45
【问题描述】:

我有这个步骤:

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

为了简化,我尝试将response.requests[0].request 放入一个名为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"}

我遇到以下错误:

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

我阅读了documentation 并且request 的使用似乎没问题:

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

我做错了什么?

提前致谢。

【问题讨论】:

  • 我自己是否有任何问题不被接受?

标签: karate


【解决方案1】:

只需进行此更改:

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

我们只是禁止def request(使用request 作为变量名),因为很多新手用户会感到困惑。错误消息在 99.9% 的时间内都有效,让用户了解问题所在,但我猜你属于 0.1% :)

【讨论】:

  • 也许我属于 0.1% 的人,他们认为当我们写“def something =”时,某些东西实际上是一个变量,或者至少我们期望一条错误消息说请求是一个保留字: )
  • @italktothewind 我承认这可以改进,所以在下一个版本的空手道中会这样:github.com/intuit/karate/commit/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-19
  • 1970-01-01
  • 1970-01-01
  • 2021-02-16
相关资源
最近更新 更多