如何在空手道中使用参数在其他文件中调用JS函数?
我有一个空手道功能,需要通过JS文件的参数调用JavaScript函数。不在功能本身中。想要在单独的文件中组织许多JS函数,并从功能文件中调用它。就像用黄瓜创建Java步骤定义一样。
Feature: Inside new
Background:
* def result = call read(‘GetTokens.feature')
Given url devURL
* def at = result.access_token
* def rt = result.refresh_token
* def data = read('classpath:src/main/resources/GetHeaders.js', at, rt)
* configure headers = data
Scenario Outline: new
Given path ‘new’
And request ‘’
When method post
And status 201
此功能称为getheaders.js,但无法阅读参数。被称为的方式有什么问题。或空手道框架/Nashorn无法支持。
#GetHeaders.js
var f1 = function(at, rt){
var head = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'token': at,
'refresh-token': rt,
'channel': 'online'
}
return head
}
I have a karate feature which needs to call a JavaScript function with arguments from js file. Not in the feature itself. Want to organise many js function in separate file and call it from a feature file. Just like creating java step definitions with cucumber.
Feature: Inside new
Background:
* def result = call read(‘GetTokens.feature')
Given url devURL
* def at = result.access_token
* def rt = result.refresh_token
* def data = read('classpath:src/main/resources/GetHeaders.js', at, rt)
* configure headers = data
Scenario Outline: new
Given path ‘new’
And request ‘’
When method post
And status 201
This feature calls GetHeaders.js But not able to read the arguments. Is there anything wrong with the way it's been called. Or karate framework/nashorn can't support.
#GetHeaders.js
var f1 = function(at, rt){
var head = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'token': at,
'refresh-token': rt,
'channel': 'online'
}
return head
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将JS代码移至功能文件中的功能。就像其他任何JS或Java函数一样,可以使用任意数量的参数来调用该函数。以下是您需要任何参考的示例代码。
Move the js code to a function within a feature file. The function can be called using any number of arguments just like any other js or java functions. Below is the sample code incase you want any reference.
尝试以这种格式调用JS代码。它应该起作用
Try calling the js code in this format. It should work
空手道不支持从外部文件调用JS方法
karate does not support calling js methods from external files