karateframework:将从csv读取的值作为参数传递给javaprogram [英] karateframework:Pass values read from csv as arguments to javaprogram

查看:153
本文介绍了karateframework:将从csv读取的值作为参数传递给javaprogram的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用空手道框架将值作为参数动态传递给Java程序.

How to pass values as parameters dynamically to java program using karate framework.

我正在尝试从csv文件读取数据.转换成json格式

I am trying to read the data from csv file. which is converted to json format

Csv数据

FirstName,MiddleName,LastName
"John","K","Kennady"
"Mahesh","g",Readdy"

* def csvData = read('csv Data')
* read csvData

读取的csvData的输出

Output of read csvData

[{"FirstName" : "John","MiddleName" : "K", "LastName" : "Kennady"},{"FirstName" : "Mahesh","MiddleName" : "g", "LastName" : "Readdy"}]

我能够从json中提取值,结果看起来像这样

I am able to extract the values from json and the result looks like this

values = ["John", "K", "Kennady"]

我应该将值作为参数传递给下面的命令JavaDemo.doWorkStatic

I should pass the values as paramters to below command JavaDemo.doWorkStatic

* def JavaDemo = Java.type('com.mycompany.JavaDemo')
* def result = JavaDemo.doWorkStatic('Firstname','MiddleName','lastname')

在javascript中,我们可以将array分配给array,而array可以分配给java的参数.但是下面的步骤在karateframework中是不可能的

in javascript we can assign array to array which can assign to arguments for java . But the below step is not possible in karateframework

[a, b ,c ] = Values
cosnole.log(a)
cosnole.log(b)
cosnole.log(c)
def result = JavaDemo.doWorkStatic(a,b,c)

我如何实现将值作为参数传递的最后一步

推荐答案

在这里:

* def v = ['John', 'F', 'Kennedy']
* def result = JavaDemo.doWorkStatic(v[0], v[1], v[2])

空手道不是JavaScript.如果您要更改任何内容,请提供代码.

Karate is not JavaScript. Please contribute code if you want to change anything.

请注意,JSON数组会自动转换为Java List -s.请阅读文档: https://github.com/intuit/karate#calling-java

note that JSON arrays are auto-converted to Java List-s. Please read the docs: https://github.com/intuit/karate#calling-java

例如,如果您有以下内容:

For example if you have this:

public static String concat(List<String> list) {
    StringBuilder sb = new StringBuilder();
    for (String s : list) {
        sb.append(s);
    }
    return sb.toString();
}

您可以执行以下操作:

* def array = ['a', 'b', 'c']
* def res = Utils.concat(array)

这篇关于karateframework:将从csv读取的值作为参数传递给javaprogram的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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