我试图在 testcafes API 中找到类似于 Cypress 请求的方法。
柏'request https://docs.cypress.io/api/commands/request.html#Cookies会将任何 cookie 附加到浏览器中已存在的请求中,以便 http 请求看起来像是从浏览器/用户发出的。
testcafe中有类似的功能吗?
您可以使用以下方式修改您的 cookie客户端功能 https://testcafe.io/documentation/402832/guides/basic-guides/obtain-client-side-info机制。这些 cookie 将添加到进一步的请求中。这种方法是安全的,因为TestCafe中的每个测试都是从清除cookie开始的,因此cookie的修改不会影响其他测试。
我准备了一个例子,请看:
import { ClientFunction } from 'testcafe';
const setCookie = ClientFunction(() => {
document.cookie = "myCustomCookie=myCustomValue";
});
fixture `fixture`
.page `http://google.com`;
test(`1`, async t => {
await setCookie();
await t.typeText('input[type=text]', 'test');
await t.debug();
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)