[英]How to get httpOnly (secure) cookies TestCafe?
出于测试目的,我必须在成功通过身份验证后立即检索 HttpOnly 和 Secure cookie。 正如预期的那样, ClientFunction(() => document.cookie)
不起作用。 由于 TestCafe 是一个代理,因此应该有一种方法可以访问这种 cookie。 我如何到那里?
目前,TestCafe 不具备获取安全 cookie 的能力。 我们对此有一个功能建议。 请关注https://github.com/DevExpress/testcafe/issues/4428问题。
我的解决方法是使用 RequestLogger。 例如:
import { Selector, RequestLogger } from 'testcafe';
// Want everything from example.com
const logger = RequestLogger(/example.com/, {
logResponseHeaders: true,
logResponseBody: true
// Do not set stringify response body if your response
// comes as gzip or brotli or whatever, instead you
// will need to use Node's zlib to unzip it and read it
});
fixture `My test`
.page `https://example.com`
.requestHooks(logger);
test(`Log in and retrieve cookies`, async t => {
await t
// Do things here
.click(...)
const requests = logger.requests
for (const req of requests) {
console.log('Headers: ', req.response.headers)
for (const cookie of req.response.headers['set-cookie']) {
// You will have to parse the cookie yourself
console.log(cookie)
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.