Skip to content
Advertisement

Testcafe Getting all Cookies from domain, store them in Object / Array and check if the Names of the Cookies are in an Array

I am new to Testcafé and need to get all Cookies from a Website, store them in an Object or Array and see, if the name of the Cookie matches against an Array of Strings to see if some Cookies are set; this needs to be done in Typescript; in pure Javascript would be easier, but these are the Requirements.

In order to achieve this, I implemented an Interface with all the Properties that I need from the Cookies:

JavaScript

This is the implementation for the Testcase I came up with so far:

JavaScript

TODO: Implement a Function that gets all the Cookies or uses the Interface and compare the property name against an Array of Strings )

JavaScript

This is were I am stuck at the moment and would hence appreciate any hints or help, especially on how to get the Names from all the Cookies and compare them to an Array of Strings; thanks in advance!

Advertisement

Answer

Since TestCafe 1.19.0 version there is no need to invent complicated workarounds to interact with the browser cookies. Our cookie management API offers a flexible and cross-browser way to set, get, or delete page cookies even those with the HttpOnly attribute. Read more in the Release notes.

The following example shows a common case of working with cookie.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement