Tar*_*ran 1 javascript dsl karate
我不确定如何从已创建的功能中拆分响应字符串以获取响应标头“位置”值。
我试过的
1)
Feature: Create Tariff
Background:
* def result = call read('../../get-user-token.feature')
* def serviceId = call read('create-service.feature')
Scenario: Create Tariff
Given url 'https://app-dev.topbox.pro/tariff-svc/api/v1/tariffs'
And header Authorization = result.response.token_type + " " + result.response.access_token
And request
"""
{
serviceTypeId: '#(serviceId.responseHeaders['Location'].split('/')[1])',
owner: 1,
type: 0,
pencePerMile: '69.69',
minMileage: '1.00',
minCost: 5,
zoneFrom: '',
zoneTo: '',
fixedCost: 0
}
"""
When method POST
Then status 201
Run Code Online (Sandbox Code Playgroud)
这导致...
IntegrationTests.TestSetup.create-tariff:create-tariff.feature:10 - net.minidev.json.parser.ParseException:位置 46 处出现意外标记 L。
2)
Feature: Create Tariff
Background:
* def result = call read('../../get-user-token.feature')
* def serviceId = call read('create-service.feature').responseHeaders['Location'].split('/')[1]
Scenario: Create Tariff
Given url 'https://app-dev.topbox.pro/tariff-svc/api/v1/tariffs'
And header Authorization = result.response.token_type + " " + result.response.access_token
And request
"""
{
serviceTypeId: '#(serviceId)',
owner: 1,
type: 0,
pencePerMile: '69.69',
minMileage: '1.00',
minCost: 5,
zoneFrom: '',
zoneTo: '',
fixedCost: 0
}
"""
When method POST
Then status 201
Run Code Online (Sandbox Code Playgroud)
这导致...
失败的功能:IntegrationTests.TestSetup.create-tariff:-unknown-:5 - javascript 评估失败:read('create-service.feature').responseHeaders['Location'].split('/') 1,TypeError:不能从第 1 行的 undefined 中读取属性“Location”
注意 指定的特性“create-service.feature”在隔离时确实起作用并且确实产生响应头,如下所示
使用lastIndexOf代替split:
* def location = responseHeaders['Location'][0]
* def serviceId = location.substring(location.lastIndexOf('/') + 1)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3148 次 |
| 最近记录: |