通过不同的方案传递定义的变量是行不通的 [英] Passing defined variable through different scenarios is not working

查看:141
本文介绍了通过不同的方案传递定义的变量是行不通的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用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 Scenarios 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆