有没有办法使用 Karate DSL 获取 sessionStorage?

2023-12-21

我当前需要获取 sessionStorage 密钥下保存的身份验证令牌,并将其用于其他 API 调用。我使用 Karate UI 自动化来访问浏览器并访问该页面,但无法访问 sessionStorage。我也想过用一些JS来获取它,但我不确定是否可行。有人有什么想法吗?


应该很容易使用script()。我刚刚在测试中尝试了这两个语句,效果很好:

* script("sessionStorage.setItem('foo', 'bar')")
* match script("sessionStorage.getItem('foo')") == 'bar'

我使用的是 0.9.5.RC5 版本,文档在这里:https://github.com/intuit/karate/tree/develop/karate-core#script https://github.com/intuit/karate/tree/develop/karate-core#script

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

有没有办法使用 Karate DSL 获取 sessionStorage? 的相关文章