我正在使用空手道API框架的路径关键字来发出请求。路径存储在一个变量中,该变量从另一个特性文件返回。然而,我不能通过"?"。下面是我正在做的:
我有一个'paths。功能'文件,获得所有路径为我的后续请求。下面是返回路径的示例:
/LegalEntity/{legalEntityId}/taxidentifier/{Id} ? formId = captureCustomerContact& subformid = taxIdentifierSimplified
I then "replace"参数如下:
/LegalEntity/43/taxidentifier/13 ? formId = captureCustomerContact& subformid = taxIdentifierSimplified
然后我从一个新的特征文件中调用这个特征文件,并将存储的变量(def)传递到路径中,但是,URL不会忽略'?’测试失败了。任何指示或帮助将不胜感激。由于
误差
/LegalEntity/43/taxidentifier/13% 3 fformid = captureCustomerContact& subformid = taxIdentifierSimplified
我想你是困惑了,这与调用一个特性无关。
当path
中有特殊字符时,它将被编码。这就是HTTP的工作原理。参见:https://stackoverflow.com/a/54477346/143475
试试下面的3行测试,看看会发生什么:
* url 'https://httpbin.org'
* path 'anything/?'
* method get
实际发送的URL将是:https://httpbin.org/anything/%3F
但是您需要了解,当您正确使用param
关键字时,?
将自动插入:
* url 'https://httpbin.org'
* path 'anything'
* param foo = 'bar'
* method get
这里的URL是:https://httpbin.org/anything?foo=bar
所以你应该做的是重构你的测试,传递formId
和subformid
作为查询参数,例如:
* def someVariable = 'captureCustomerContact'
* url 'https://httpbin.org'
* path 'anything'
* param formId = someVariable
* method get
请花点时间研究一下这是如何工作的。这里的URL将是https://httpbin.org/anything?formId=captureCustomerContact
,当然,您可以有更多的param
实例。请阅读文档:https://github.com/karatelabs/karate#param