空手道特征文件中如何使用.js文件中的参数调用Javascript函数 [英] How to call a Javascript function with arguments from .js file in karate feature file
问题描述
假设我在功能js文件中创建了javascript函数.
Lets say I created javascript functions in functions js file.
函数getReviews(评论){
var length_reviews = reviews.length返回length_reviews}
函数getReviewsLength(reviewLength){
返回评论长度}
函数 getReviews
中的参数 reviews
此处是一个数组.现在,我将如何在一个功能文件中调用 getReviews
函数.当我尝试以下代码时
Here in function getReviews
argument reviews
is an array.
Now how will I call getReviews
function in one feature file.
When I tried below code
* def jsFunction =调用read('functions.js')* def评论= jsFunction.getReviews(reviewFromFeatureFile)
我收到
无法从未定义中读取属性"length"
我已经打印了 reviewFromFeatureFile
并将其正确显示在打印语句中.
I already printed reviewFromFeatureFile
and its coming correctly in print statement.
推荐答案
如上述Peter所述,您可以将js内联在功能上
As Peter mentioned above you can keep you js inline on your feature
* def reviews = [{"r1":2},{"r1":3},{"r1":4}]
* def getReviews = function(reviews){ return reviews.length }
* def getReviewsLength = getReviews(reviews)
* print getReviewsLength
在此示例中,它应打印3.
In this example, it should print 3.
有关在空手道中处理javascript或其他可重用模块的更多其他选项,请参阅本文
For more other options for handling javascript or other reusable modules in karate, please refer to this article
这篇关于空手道特征文件中如何使用.js文件中的参数调用Javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!