本文介绍了如何在responseHeaders位置中获取ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于我的POST请求,在responseHeaders中,我得到1 < location: /users/123
我只想打印id> 123.当我在功能文件中执行* print responseHeaders['location'][0]
时,得到users/123
.我怎样才能只获得身份证?
解决方案
这不是一个空手道问题吗?
尝试一下:
* def location = responseHeaders['location'][0]
* def userId = location.substring(location.lastIndexOf('/') + 1)
* print userId
是的,JavaScript(甚至通过 Java interop )可以在空手道中使用!
For my POST request, in responseHeaders I get 1 < location: /users/123
I would like to print only the id > 123.When I do * print responseHeaders['location'][0]
in my feature file, I get users/123
. How I can get only the id?
解决方案
This is not really a Karate question is it :P
Try this:
* def location = responseHeaders['location'][0]
* def userId = location.substring(location.lastIndexOf('/') + 1)
* print userId
That's right, all the power of JavaScript (or even Java via Java interop) is available to you in Karate !
这篇关于如何在responseHeaders位置中获取ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!