英文:
Karate: How to use a datatable in a java function?
问题
我有一个类似的特性文件:
* def javaFunction = Java.type('my.javaClass');
* def generateFile = new javaFunction().functionName(???)
和我的函数看起来是这样的:
public String functionName(DataTable dm){
for (DataModel aDataModel : dm) {
String username = aDataModel.user;
String password = aDataModel.password;
}
}
我想使用一个类似这样的数据表,在我的.feature
文件中,但我不确定如何在functionName(???)
中调用它:
|user |password |
|cucumber1 |cucumber |
|cucumber2 |cucumber |
希望这对你有帮助。
英文:
I have a feature file that looks like:
* def javaFunction = Java.type('my.javaClass');
* def generateFile = new javaFunction().functionName(???)
And my function looks like
public String functionName(DataTable dm){
for (DataModel aDataModel : dm) {
String username = aDataModel.user;
String password = aDataModel.password;
}
}
I want to use a Data table that looks like this but I'm not sure how to call it in the functionName(???) in my .feature file
|user |password |
|cucumber1 |cucumber |
|cucumber2 |cucumber |
答案1
得分: 1
我认为你期望Karate像Cucumber一样工作,但它并不是这样工作的。在Karate中没有DataTable
这样的东西。
请花些时间了解Karate如何使用JSON数组,以便在数据源上进行循环操作:https://github.com/karatelabs/karate#data-driven-features
还有一种方法可以实现动态的场景大纲,查阅这里:https://github.com/karatelabs/karate#setup
英文:
I think you are expecting Karate to work like Cucumber, no that's not how it works. There's no such thing as a DataTable
in Karate.
Please spend some time how Karate uses JSON arrays where you want to loop over a data source: https://github.com/karatelabs/karate#data-driven-features
And there is a way to do dynamic scenario outlines, look it up: https://github.com/karatelabs/karate#setup
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论