【发布时间】:2019-12-03 17:17:05
【问题描述】:
我对空手道有一点棘手的要求。我的 karate.config 中有一组 baseURL,它们是根据实现选择的。这是它的sn-p:
if (env == 'qa') {
config.apiKey = apiKey;
config.tsp_api = 'https://api.qa.tceu.net';
config.svt_dcm = 'https://svt.qa.tceu.net';
config.acn_dcm = 'https://acn.qa.tceu.net';
config.sos_dcm = 'https://sos.qa.tceu.net';
config.cust_dcm = 'https://cust.qa.tceu.net';
这里 tsp,svt,acn,sos,cust 是一些动作。
我有一个将动作作为参数传递的功能文件:
# Vehicle Initiates the action
When def Perform_Report_Notification = call read('./../common/performActionNotification.feature') { action: '#(action)' }
在调用的 performActionNotification.feature 中,我需要根据传递的操作从 karate.config 文件中获取 url。例如,如果 action 是 sos,那么 url 应该是 sos_dcm。如果 action 是 svt 那么 url 应该是 svt_dcm
这是 performActionNotification.feature 中的 sn-p 以及我目前正在为 sos 做的事情:
Given url sos_dcm
And path '/AU/v1.0/TSP/'+ action
And request RequestPayload
When method post
Then status 200
我想实现类似于 if then else 的东西:
if (action == 'sos')
then myurl == 'sos_dcm'
else if (action == 'acn')
then myurl == 'acn_dcm'
else if (action == 'svt')
then myurl == 'svt_dcm'
Given url myurl
And...
And...
...
我尝试了一种 hack,它可以工作,但它不是一种干净的方式。我没有从 karate.config 读取 URL,而是以这种方式对其进行硬编码:
Given url 'https://'+act+'.qa.tceu.net'
我尝试的另一件事是
* def myurl = action +'_dcm' #so if action is acn then the variable myurl would be acn_dcm
Given url myurl
...
....
但这会将 url 硬编码为“acn_dcm”,而不是从 karate.config 中选择定义的 url。
有人可以建议最好的实现方式吗?
【问题讨论】:
-
老实说,不确定这是否值得。如果您对正在更改的 url 的一部分使用变量,您仍然需要在某处进行设置。
标签: karate