如何在soap ui中的groovy脚本之间传递二维列表/数组? [英] How to pass a two dimensional list/array between groovy scripts in soap ui?

查看:184
本文介绍了如何在soap ui中的groovy脚本之间传递二维列表/数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题陈述:我们需要一种方法将一个groovy脚本的二维列表(或数组)传递给其他脚本(以在其他脚本中声明来自多个DB2表的值)。



一些背景:
Step1:根据我们输入的xml负载,我们在二维列表[] []中捕获节点列表(和子元素)。[完成]
Step2 :现在我们想要使用这个列表中的每个值来声明DB2表中的值[但是,同样要保持step1和step2在同一个groovy脚本中]。



我们想要的是能够在步骤2中从step1传递2维列表。特别重要的是,我们有多个表,并且我们不想在一个大的groovy脚本中添加所有表步骤或者在每个步骤中复制step1代码Db2 validataion脚本。



我们阅读了关于在测试用例级别设置列表中每个元素值然后重新构建数组的方法,但由于(va行进和)巨大的列表元素(以千计)。问题是:有没有干净的方法来实现这一目标?



谢谢!

解决方案

您可以使用 context



这是真正有效的 Groovy Script 步骤。



step1:

  def array = ['Kyiv','Boryspil','Kharkiv' ,L'Viv,Odesa] 
context.setProperty('cities',array)
log.info('script1:'+ array)

step2:

  def数组=上下文。 getProperty('cities')
log.info('script2:'+ array)
assert array.size()> 0




注意:

如果只运行一步,那么将会有绝对
独立上下文。



但是,如果您运行整个测试用例,那么在整个测试用例中将会共享上下文


<您可以在测试用例窗口中使用从这里运行上下文菜单从精确的步骤运行。



Problem statement: We need a way to pass a two dimensional list (or array) from one groovy script to other scripts ( to assert values from multiple DB2 tables in other scripts].

Some Background: Step1: Based on our input xml payload we are capturing the list of nodes (and child elements) in a two dimensional list [][]. [Done] Step2: Now we want to use the values from each of this list to assert with respect to values in DB2 tables [Also done, however keeping both step1 and step2 in same groovy script].

What we want is to to be able to pass the 2dimensional list from step1 in step2. Specially important since we have multiple tables and we dont want to either add all table steps in one big groovy script Or to duplicate step1 code in each Db2 validataion script.

We read about setting each element value from list at test case level and then reconstructing the array back but we are hesitating to use that method due to (varying &) huge size of list elements (in thousands). Question is: Are there any clean ways to achieve this?

Thanks!

解决方案

You can use context

That's real working Groovy Script steps.

step1:

def array = ['Kyiv', 'Boryspil', 'Kharkiv', "L'Viv", "Odesa"]
context.setProperty('cities', array)
log.info( 'script1: '+array )

step2:

def array = context.getProperty('cities')
log.info( 'script2: '+array )
assert array.size()>0

Note:

If you run just one step, then there will be absolutely independent context.

But if you run the whole testcase then there will be context shared for the whole testcase.

You can use Run from here context menu in your test case window to run from exact step.

这篇关于如何在soap ui中的groovy脚本之间传递二维列表/数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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