通过不同的方案传递定义的变量是行不通的 [英] Passing defined variable through different scenarios is not working
问题描述
尝试使用PATCH方法将POST场景的响应引用传递给另一个场景,并更改其中一个属性并获取错误。对源代码进行补偿我发现当为一个场景调用Scripts.assign时,变量作用域不会传递给另一个场景。
Trying to pass a reference of the response of a POST scenario to another scenario with PATCH method and changing one of the properties and getting errors. Debbuging the source code i found that when Scripts.assign is called for one scenario, the variable scope doesn't pass to the another scenario.
- 空手道版本: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'}
推荐答案
这是设计 - 如果您需要变量位于功能中所有 Scenario
的范围内,请将其移至背景
。如果您希望此变量仅初始化一次,请查看 callonce
关键字。
This is by design - if you need variables to be in the scope for all Scenario
s within a feature, move it to the Background
. And if you want this variable to be initialized only once, look at the callonce
keyword.
这篇关于通过不同的方案传递定义的变量是行不通的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!