Cookies are a type of message given to a web browser by a web server. They aim to identify users and potentially prepare customized web pages to prevent the user from having to re-enter information.
Why are they useful?
Cookies essentially customize your web experience! For example, if you visit an online shop for the first time, the site's server sends a file to your computer and automatically installs this file on your machine. As a result, you'll be recognized as a returning visitor the next time you visit the website, and you won't have to re-enter your information.
How many kinds of cookies are there?
There are three main types of cookies: session, permanent, and third-party cookies.
- Session cookies are primarily used by online shops, and expire when the browser is closed.
- Permanent cookies are the kind that remain in operation even after closing the browser. They remember your anonymous user ID or login credentials so you can be easily identified and/or authenticated every time you visit a site.
- There are also third-party cookies, which are installed by external parties that collect certain user information on demographics and behavior.
You can use the mabl Trainer to set cookies and make assertions against cookies and cookie attributes.
Chrome is phasing out support for third-party cookies by Q3 2024. For more information, including instructions on how to audit your web app’s third-party cookie usage, click here.
How to set a cookie
- Click on the plus icon at the bottom of the mabl Trainer window to add a step.
- Click on the Cookies step.
- Select the Set cookie option.
- Fill out the name and value. If you want to set the name or value to an existing variable's value, use mabl variable syntax: `
- If you want to customize cookie attributes, toggle on "Set advanced options" and customize the attributes you want to set.
- Click OK to save the cookie.
Verifying cookies with assertions
If you want create an assertion for a cookie, you can take the following steps:
- Click on the check mark icon at the bottom of the mabl Trainer window to create a new assertion.
- Select Cookie to assert against a cookie.
- Select a cookie from the drop-down menu to view its attributes. The Trainer will automatically populate this drop-down with a list of all cookies that are associated with the current page.
Selecting a cookie
- Click OK.
- Configure the assertion type, property, and value to compare against. Additional options include disable case sensitivity and continue on failure. See the main article on assertions for more details.
Configuring the cookie assertion
- Click OK. You'll now see a step in your test containing the cookie assertion.