无法更新被调用功能中的变量 [英] unable to update variables in a called feature

查看:37
本文介绍了无法更新被调用功能中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按照演示中的示例进行操作: https://github.com/直觉/空手道/树/主/空手道演示/src/test/java/demo/callfeature 我需要从一个功能调用到另一个功能,并传递参考以进行更新.该引用适用于从文件读取的JSON:

I am trying to follow the examples in the demo: https://github.com/intuit/karate/tree/master/karate-demo/src/test/java/demo/callfeature I need to do a call from one feature to another, and pass a reference to update. The reference is for a JSON that is read from a file:

  Background: 
    * url url
    * header Authorization = token
    * def payload = read('event.json')
    * set payload.createdByUser = 'karate'

  Scenario: Call another feature with arg
    * call read('classpath:common/swap-json-elements.feature') payload
    * print payload

在我的swap-json-elements.feature里面:

Inside my swap-json-elements.feature:

  Background: 
    * set new = payload.old
    * set payload.new= payload.old
    * set payload.old= new

这不起作用.在文档中很清楚的是,使用设置"时共享的作用域是共享的,而"def"将创建一个新变量,并且从不更新共享的作用域.

This is not working. It is clear in the documentation that a shared scope is shared when we 'set' is used, while 'def' will create a new variable, and never update the shared one.

我想念什么?

推荐答案

如果传递参数,则按值传递.当您使用共享范围" call时,通常不需要传递参数.因为无论如何所有变量都是可见的.尝试一个简单的示例,请注意=符号周围的空白.

If you pass an argument, it is passed by value. When you call with "shared scope" you typically don't need to pass arguments. Because all variables are visible anyway. Try a simpler example, and please watch white-space around the = sign.

main.feature:

Feature:

Background:
* def json = { foo: 'bar' }
* call read('called.feature')

Scenario:
* match json == { foo: 'baz' }

called.feature

Feature:

Scenario:
* set json.foo = 'baz'
* match json == { foo: 'baz' }

这篇关于无法更新被调用功能中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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