How to call a particular javascript function from .js file in karate feature file

时光毁灭记忆、已成空白 提交于 2019-12-01 09:43:42

问题


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()

回答1:


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' }
  }
}

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



来源:https://stackoverflow.com/questions/47000036/how-to-call-a-particular-javascript-function-from-js-file-in-karate-feature-fil

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!