Skip to main content

Setting Cookies For Page Tests

Setting cookies when testing your page can be useful in many situations, for example:

  • to opt into a specific A/B test
  • to test a page with user preferences saved
  • to skip a consent banner

Option 1: running a JavaScript snippet on the page

Injecting a JavaScript snippet is the quickest way to set a cookie.

You can find this option in the advanced settings of your page setup.

Create script

Select Add Script, Create Script, and then assign a value to document.cookie.

Setting document.cookie

Limitations of this approach

The on-page script runs only when the document starts loading. The cookie will not be sent as part of the initial document request.

Option 2: use a setup flow

Setup flows run before the main performance test starts. Rather than injecting code on the page, setup flows allow you to interact with the UI elements on the page, causing the page to set the relevant cookies.

They are the best solution when you want to set a session cookie by filling out a login form or add items to the shopping cart before testing the performance of the checkout page.