我想使用空手道框架创建一个动态网址。 假设我要创建的URL是:
https://www.mars.com/mars/profile/{profileID}/line
在上面的URL中{profileID}
是路径。
目前,我已经编写了以下功能文件,该文件能够创建URL,但是由于使用路径关键字,它会对URL进行编码并在配置文件ID后添加%0A
。
https://www.mars.com/mars/profile/264%0A/line
功能文件:
@smoke
Scenario: Create a line score in existing profile
And def urlname = marsuri+ '/mars/profile/'
Given url urlname
Given path id + '/line'
请让我知道如何在不对其进行编码的情况下创建 URL 之间有路径的 URL。
您没有正确使用path
语法。请阅读文档:https://github.com/intuit/karate#path
进行此更改:
Given path id, 'line'
编辑:另请参阅此答案:https://stackoverflow.com/a/54477346/143475
实际上,无论您从哪里获取变量,id
变量都在字符串末尾有一个新行,类似于这样"264n"
这就是为什么它被编码为264%0A
如果您只想传递"264"
则必须删除不需要的值,然后再将其添加到path
Background:
* def removeNewLine = function(x){return x.replace("n","")}
Scenario: Create a line score in existing profile
And def urlname = marsuri+ '/mars/profile/'
Given url urlname
* def id = removeNewLine(id)
Given path id + '/line'
如果可以直接从获取id
的源修改数据,那就太好了。