空手道特征文件中如何使用.js文件中的参数调用Javascript函数

编程入门 行业动态 更新时间:2024-10-27 03:37:05
本文介绍了空手道特征文件中如何使用.js文件中的参数调用Javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

本文发布于:2023-05-31 22:07:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/400266.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   空手道   如何使用   函数   特征

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!