2

尝试使用 PATCH 方法将 POST 场景的响应的引用传递给另一个场景并更改其中一个属性并出现错误。调试源代码时,我发现当为一个场景调用 Scripts.assign 时,变量范围不会传递给另一个场景。

  • 空手道版本:0.5.0
  • Java版本:1.8

测试的全部功能:

Feature: Products CRUD Test

Background: 
  * url demoBaseUrl

Scenario: fetch some products
  Given path 'products'
  When method get
  Then status 200
  And assert response.size() === 6

Scenario: add a product
  Given path 'products'
  And request {name: 'Iphone 7 Plus 128GB', description: 'Iphone 7 Plus Space Gray 128GB' }
  When method post
  Then status 200
  And match response contains { id: '#number', name: 'Iphone 7 Plus 128GB', description: 'Iphone 7 Plus Space Gray 128GB'}
  And def newProduct = response

Scenario: update a product
  Given path 'products'
  And def payload = {name: '#(newProduct.name)', description: '#(newProduct.description)'}
  And set payload $.id = #(newProduct.id)
  And match payload.id == (newProduct.id)
  And request payload
  When method patch
  Then status 200
  And match response contains {name: 'New Product Iphone 7'}
4

1 回答 1

1

这是设计使然 - 如果您需要变量在Scenario功能内所有 s 的范围内,请将其移至Background. 如果您希望这个变量只初始化一次,请查看callonce关键字。

于 2017-08-02T00:51:42.783 回答