Testing Cookie Banner Screenshots with Stored Consent
In this article
When a website stores consent in a cookie, testing cookie banner screenshots becomes tricky: the banner only appears on the first visit (or after clearing cookies), and you need to verify both the initial state and the post-consent state. This guide walks you through a reliable, repeatable method to capture and verify those screenshots, covering what you need, step-by-step instructions, common pitfalls, and troubleshooting.
What You'll Need
- A browser with developer tools (Chrome, Firefox, Edge, or Safari).
- Access to the website's cookie consent implementation (either via browser DevTools or a backend admin panel).
- A way to capture screenshots (built-in browser tools, a screenshot extension, or a dedicated tool like Selenium or Playwright if you're automating).
- Optional: a clean browser profile or incognito window to ensure no existing cookies interfere.
Step-by-Step
- Identify the consent cookie name. Open the website in a normal window, accept cookies, then open DevTools (F12) → Application (Chrome) or Storage (Firefox) → Cookies. Look for a cookie that contains something like "consent", "cookie_consent", "gdpr", or similar. Note its name and value (e.g.,
cookie_consent=accepted). If you can't find it, check the Network tab for a Set-Cookie header when you click accept. - Set up a clean test environment. Open a new incognito/private window (or use a separate browser profile) to ensure no cookies from previous sessions exist. This gives you the "first visit" state where the banner should appear.
- Capture the initial banner screenshot. Navigate to the page where the banner appears. Wait for the banner to fully load (including any animations). Take a screenshot that shows the banner in its default state—no consent given yet. Save it with a clear name like
banner-initial.png. - Accept or decline consent. Click the appropriate button on the banner (e.g., "Accept All" or "Reject"). This action should set the consent cookie with a specific value.
- Verify the cookie was set. Open DevTools → Application → Cookies again. Confirm the consent cookie now exists with the expected value (e.g.,
acceptedorrejected). If the cookie is not set, the banner may not be functioning correctly—see Troubleshooting. - Capture the post-consent screenshot. After accepting, the banner should disappear (or be minimized). Take a screenshot of the page without the banner to document the post-consent state. Save it as
banner-accepted.pngor similar. - Test the persistence. Reload the page (F5) in the same window. The banner should not reappear because the consent cookie is present. Take a screenshot to confirm. This verifies that the cookie is being read on subsequent visits.
- Test the rejection path (if applicable). If your site offers a "Reject" option, repeat steps 2–7 but click "Reject" instead. Capture the banner after rejection and verify the cookie value is different (e.g.,
rejected). - Test the "clear cookies" scenario. To simulate a returning user who clears cookies, go to DevTools → Application → Cookies, select the consent cookie, and delete it. Reload the page—the banner should reappear. Capture this as
banner-after-clear.png. - Document your results. Create a simple test report with the screenshots, the cookie name/value, and the expected behavior at each step. This helps your team or QA verify that consent handling works as intended.
Common Mistakes
- Not using a clean session. If you test in a window where the cookie already exists, the banner won't show, and you'll waste time wondering why.
- Confusing cookie values. Some sites use a single cookie with multiple values (e.g.,
consent=necessary:1,analytics:0). Make sure you're checking the correct part. - Capturing too early. If the banner has a fade-in animation, a screenshot taken immediately may show a partially transparent banner. Wait for the animation to finish.
- Ignoring the difference between session and persistent cookies. Some consent cookies are session-only (deleted when the browser closes). If you close the browser and reopen, the banner will appear again—this may be intentional, but document it.
- Forgetting to test on different pages. The banner might behave differently on subpages (e.g., a cookie policy page). Test at least two different pages.
Tips
- Use a screenshot tool that captures the full viewport. Some tools only capture the visible area; if the banner is fixed at the bottom, you might miss it.
- Automate with Playwright or Puppeteer. If you need to repeat this test regularly, write a script that sets the cookie manually, loads the page, and takes screenshots. This is faster and less error-prone.
- Check the cookie's HttpOnly flag. If the cookie is HttpOnly, you can't see it in DevTools' Application tab (but you can see it in the Network tab's Set-Cookie header). Adjust your verification method accordingly.
- Take note of the cookie's expiration. If the cookie has a long expiration (e.g., 1 year), that's fine. If it's a session cookie, document that the banner will reappear after browser restart.
- Use a test environment. Don't test on production if you can avoid it—you might accidentally set consent cookies for real users.
Troubleshooting
- Banner doesn't appear even in incognito. Check if the site uses a server-side consent flag (e.g., based on IP or user agent). If so, you may need to clear site data in your normal profile or use a different network. Also check if the banner is hidden behind a cookie wall that requires JavaScript—enable JavaScript in your browser.
- Cookie is set but the banner still shows. This usually means the site is not reading the cookie correctly. Open DevTools → Network, reload the page, and look at the request headers—does the cookie get sent? If not, the cookie may be scoped to a different path or domain. Check the cookie's Path attribute (e.g., if it's set to
/subdir, it won't be sent on the homepage). - The cookie value changes after reload. Some sites update the cookie's value to reflect user choices on each page load. If you see the value change, that's normal—just ensure the "consent given" flag remains.
- Can't find the cookie in DevTools. The cookie might be HttpOnly, which means JavaScript can't read it, but DevTools should still show it in the Application tab. If it's not there, look at the Network tab's Set-Cookie response header to see the exact name and value.
- Screenshots look different from what users see. This can happen if you're testing on a different viewport size or device. Use the device toolbar in DevTools to simulate a mobile viewport if needed.
Frequently Asked Questions
How do I know if the consent cookie is HttpOnly?
In DevTools' Application tab, the cookie list shows an "HttpOnly" column. If it says "Yes", the cookie cannot be read by JavaScript, but it's still sent in HTTP requests. You can verify its presence via the Network tab.
Can I test without incognito mode?
Yes, but you must manually delete the consent cookie before each test. Use DevTools → Application → Cookies, right-click the cookie, and delete it. Reload the page to see the banner.
What if the banner is part of a third-party script (e.g., a consent management platform)?
Third-party scripts often store consent in their own cookies (e.g., _consent). The same steps apply—just find the cookie name from the script's documentation or by inspecting the Set-Cookie header.
How do I capture a screenshot of the banner if it disappears on scroll?
Use a screenshot tool that captures the full page, or take the screenshot immediately after the page loads before scrolling. Alternatively, use the browser's built-in screenshot feature (e.g., Ctrl+Shift+S in Chrome) to capture the visible viewport.
Is it enough to test in one browser?
No, cookie behavior can vary by browser. Test at least in Chrome and Firefox, and ideally Safari, since Safari has stricter ITP (Intelligent Tracking Prevention) that may affect cookie lifetimes.
What if the site uses localStorage instead of cookies for consent?
This guide is specifically for cookies, but the same logic applies: clear localStorage (DevTools → Application → Local Storage) to reset the consent state, then take screenshots.