如何从空手道特征文件中的.js文件调用特定的javascript函数 [英] How to call a particular javascript function from .js file in karate feature file

查看:85
本文介绍了如何从空手道特征文件中的.js文件调用特定的javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我已将以下函数保存在Utility js文件中.

Suppose I have saved followings functions in a Utility js file.

function getCurrentDate(){
return 'date';
}

function getMonth(){

return 'Oct';
}

请帮助我如何在功能文件中访问这些方法中的任何一个.

Please help me how any of these methods can be accessed in feature file.

我尝试了以下代码,但无法正常工作.

I tried following code but it is not working.

* def fun = call read('Utility.js')

* def result = getData()
or
* def result = fun.getData()

推荐答案

在Karate中,一个JS文件只能包含一个函数,并且不需要名称,请仔细阅读示例.

In Karate, a JS file can contain only one function and it does not need a name, take a closer look at the examples.

我实际上不建议将多个功能组合到一个文件中,这只会使事情变得更难维护.但是,如果您真的坚持,那就是这样:

I don't really recommend combining multiple functions into one file, it just makes things much harder to maintain. But if you really insist, here's how:

function() {
  return {
    getCurrentDate: function(){ return 'date' },
    getMonth: function(){ return 'month' }
  }
}

一个更好的答案在这里: https://stackoverflow.com/a/49384760/143475

a much better answer is here: https://stackoverflow.com/a/49384760/143475

这篇关于如何从空手道特征文件中的.js文件调用特定的javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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