空手道UI-设置cookie()时cookie域无效



我正在使用为API测试实现的现有登录功能,在功能文件中设置UI测试的cookie。类似于空手道文档中以及本线程中所描述的"混合方法"-空手道UI-根据不同的scnearios 维护浏览器cookie/会话/本地存储变量值

我的功能文件是:

Feature: UI one time login test
Background:
# I am using the existing login functionality. I perform a onetime login in karate-config and store the cookie in a config variable and assign that to token variable defined below.
* def token = { value: '#(userAuthInfo.authSession)' }
# Then configure chromedriver
* configure driver = { type: 'chromedriver', showDriverLog: true, webDriverSession: { capabilities: { alwaysMatch: { acceptInsecureCerts: true } } } }
# Set the cookie
* driver 'about:blank'
* cookie({ name: 'SESSION', value: token.value, domain: 'localhost' })
Scenario: Visit url - 1
# webBaseUrl is defined in config
* driver webBaseUrl + 'url1'

当我运行此功能并检查日志时,我可以看到正确的请求数据被传递到/cookie端点,来自web驱动程序api的响应是错误:400-无效的cookie域。我还手动在chrome中打开了我的网站,并检查了cookie的设置方式,以及它与我在cookie((方法中传递json的方式完全相同,包括域。甚至在不同的服务器上尝试使用不同的域,都会得到相同的错误。也许它不是特定于域的,因为在请求中省略域密钥会产生相同的结果。

详细信息如下:

POST请求设置cookie

14:06:36.495 [pool-1-thread-1] DEBUG com.intuit.karate - request:
4 > POST http://localhost:9515/session/c837c3e34a7dffa03fa4dc281ba0e3da/cookie
4 > Accept-Encoding: gzip,deflate
4 > Connection: Keep-Alive
4 > Content-Length: 97
4 > Content-Type: application/json; charset=UTF-8
4 > Host: localhost:9515
4 > User-Agent: Apache-HttpClient/4.5.11 (Java/1.8.0_262)
{"cookie":{"name":"SESSION","value":"cd02f1d7-6100-450b-bad9-edba8ead96b3","domain":"localhost"}}

错误400响应:

14:06:36.501 [pool-1-thread-1] DEBUG com.intuit.karate - response time in milliseconds: 4.97
4 < 400
4 < Content-Length: 1696
4 < Content-Type: application/json; charset=utf-8
4 < cache-control: no-cache
{"value":{"error":"invalid cookie domain","message":"invalid cookie domainn  (Session info: chrome=86.0.4240.111)","stacktrace":"0   chromedriver                        0x00000001080bbc29 chromedriver + 2464809n1   chromedriver                      

有什么想法吗?

可能是您可以调查并帮助我们做出更改的领域。我注意到彩色打印机很挑剔。试试壁虎驱动器,看看有没有什么不同。如果您尝试使用其他UI框架,看看我们是否缺少任何特殊处理,那将是一件非常好的事情。

一个建议是添加一个etc/hosts条目以将localhost映射到something.com并使用该域。

另请参阅:https://stackoverflow.com/a/59099843/143475

最新更新