从空手道中的 HREF URL 中提取值
Extract values from HREF URL in Karate
我在 Karate 中确实有一个查询,它将 return 对象的 self Href URL
"href": "https://domain.xyz/version/system/hwlayer/suppliers/supplier/locations/location/machines/machine"
部分响应应为下一次测试的输入数据。我需要能够提取
供应商
地点
机器
并且它们的长度不固定。我查找了帮助,但找不到我要找的内容
这不是 karate
问题。建议你下次找懂 JS 或正则表达式的人帮忙。这是一种可能的解决方案:
* def link = 'https://blah/suppliers/supplier/foo/location/bar/machine'
* def text1 = '/supplier/'
* def text2 = '/location/'
* def pos1 = link.lastIndexOf(text1)
* def pos2 = link.lastIndexOf(text2)
* def supplier = link.substring(pos1 + text1.length, pos2)
* match supplier == 'foo'
* def pos3 = link.lastIndexOf('/')
* def location = link.substring(pos2 + text2.length, pos3)
* match location == 'bar'
编辑 - 另见:
我在 Karate 中确实有一个查询,它将 return 对象的 self Href URL
"href": "https://domain.xyz/version/system/hwlayer/suppliers/supplier/locations/location/machines/machine"
部分响应应为下一次测试的输入数据。我需要能够提取
供应商 地点 机器
并且它们的长度不固定。我查找了帮助,但找不到我要找的内容
这不是 karate
问题。建议你下次找懂 JS 或正则表达式的人帮忙。这是一种可能的解决方案:
* def link = 'https://blah/suppliers/supplier/foo/location/bar/machine'
* def text1 = '/supplier/'
* def text2 = '/location/'
* def pos1 = link.lastIndexOf(text1)
* def pos2 = link.lastIndexOf(text2)
* def supplier = link.substring(pos1 + text1.length, pos2)
* match supplier == 'foo'
* def pos3 = link.lastIndexOf('/')
* def location = link.substring(pos2 + text2.length, pos3)
* match location == 'bar'
编辑 - 另见: