首页 > 解决方案 > 在空手道测试的路径中使用逗号

问题描述

使用以下测试用例

Background:
    * callonce read('auth.feature')
    * url java.lang.System.getenv('TEST_URL')

Scenario: Call the file endpoint without authorization

    Given path 'files/123695_11,8'
    When method get
    Then status 401

我收到有关引号不匹配的解析器错误。原因可能是“路径”被逗号混淆了,因为它也可以用来表示子路径。

我想过只是更改,to %2C,但随后空手道使用%编码 to调用 URL %25,导致错误的 URL'files/123695_11%252C8'解码为字面意思'files/123695_11%2C8'

我怎样才能使它正常工作?

标签: karate

解决方案


最简单的选项,合并到url

* url 'https://httpbin.org/anything/files/123695_11,8'
* method get

我知道你可能想在后台“重用”东西,所以使用变量:

Background:
* def baseUrl = 'https://httpbin.org/anything'

Scenario: 
* url baseUrl + '/files/123695_11,8'
* method get

哈克解决方法:

* url 'https://httpbin.org/anything'
* def temp = 'files/123695_11,8'
* path temp
* method get 

推荐阅读