karate - 从空手道中的 HREF URL 中提取值
问题描述
我在空手道中有一个查询,它将返回对象的 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'
推荐阅读
- python - 无法使用python找出元音计数
- html - Fetch API - 如何将 JSON 文件解析为 HTML?
- python - 来自单个/多个参数的历史相关预测
- apache-spark - Spark 中可以从 Executor 传递到 Driver 的最大数据
- postgresql - 将查询结果保存到列数未知的临时表中
- atom-editor - Atom,如何在最后一个选项卡中定位打开文件?
- powershell - powershell - 挖掘并强制使用 IPv6 或 IPv4
- shell - Unix 日期 当前日期 -(减号)日期(昨天日期)
- c++ - QListView 不显示模型中的数据
- javascript - 另一种在 html 中显示来自外部文件的内容的方法