假设我在功能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函数
发布评论