尝试使用PATCH方法将POST场景的响应引用传递给另一个场景,并更改其中一个属性并获取错误。对源代码进行补偿我发现当为一个场景调用Scripts.assign时,变量作用域不会传递给另一个场景。
测试的全部功能:
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'}
答案 0 :(得分:0)
这是设计使用 - 如果您需要变量属于要素中所有Scenario
的范围,请将其移至Background
。如果您希望仅将此变量初始化一次,请查看callonce
关键字。