有没有一种方法可以使用空手道DSL获得sessionStorage? [英] Is there a way of getting a sessionStorage using Karate DSL?
问题描述
我目前需要获取保存在sessionStorage密钥下的身份验证令牌,并将其用于其他API调用.我正在使用Karate UI自动化来访问浏览器并转到页面,但无法访问sessionStorage.我还考虑过使用一些JS来获取它,但是我不确定是否可以使用.有人有什么主意吗?
I currently need to get an authentication token that is being held under a sessionStorage key and use it on other API calls. I'm using Karate UI automation to access the browser and get to the page but I wasn’t able to access sessionStorage. I also thought about using some JS to get it, but I’m not sure if will work. Does anyone has any ideas?
推荐答案
使用script()
应该很容易.我只是在测试中尝试了这2条语句,但效果很好:
Should be easy using script()
. I just tried these 2 statements in a test and it worked fine:
* script("sessionStorage.setItem('foo', 'bar')")
* match script("sessionStorage.getItem('foo')") == 'bar'
I'm using version 0.9.5.RC5 and the documentation is here: https://github.com/intuit/karate/tree/develop/karate-core#script
这篇关于有没有一种方法可以使用空手道DSL获得sessionStorage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!