小编典典

通过不同的场景传递定义的变量不起作用

java

尝试使用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'}

阅读 217

收藏
2020-11-26

共1个答案

小编典典

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

2020-11-26