admin管理员组文章数量:1326308
I am trying to find a method in testcafes API similar to Cypress' request.
Cypress' request will attach any cookies to the request that already exist in the browser so that http requests will look like they're being made from the browser / user.
Is there a similar function in testcafe?
I am trying to find a method in testcafes API similar to Cypress' request.
Cypress' request will attach any cookies to the request that already exist in the browser so that http requests will look like they're being made from the browser / user.
Is there a similar function in testcafe?
Share Improve this question asked Jul 15, 2019 at 0:32 okayilltryokayilltry 4921 gold badge5 silver badges18 bronze badges3 Answers
Reset to default 6You can modify your cookies using the ClientFunctions mechanism. These cookies will be added to further requests. This approach is safe, since every test in TestCafe starts with clear cookies, so cookies modification will not affect other tests. I prepared an example, please see it:
import { ClientFunction } from 'testcafe';
const setCookie = ClientFunction(() => {
document.cookie = "myCustomCookie=myCustomValue";
});
fixture `fixture`
.page `http://google.`;
test(`1`, async t => {
await setCookie();
await t.typeText('input[type=text]', 'test');
await t.debug();
});
Please also take a look at https://azevedorafaela./2019/07/24/inject-cookies-in-your-testcafe-automation/?source=post_page--------------------------- . That article can be useful for your purpose.
TestCafe 1.20.0+ offers the t.request
method - it is designed for API testing. Using this method, you can incorporate API testing right into your existing functional TestCafe tests. Read about this feature in the corresponding guide.
If you'd like to attach a cookie to the request, you can use the withCredentials
option.
Please note that to get/set/delete cookies in tests, you can use TestCafe's cookie management API (works for 'HTTPOnly' as well).
本文标签: javascriptTestcafe request with cookiesStack Overflow
版权声明:本文标题:javascript - Testcafe request with cookies - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742205088a2432667.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论