Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

The reliable way to remove a cookie banner from a Cypress screenshot depends on what the image must represent. To show a genuine post-consent page, set the application’s real consent cookie before cy.visit(). To create only a clean visual artifact while leaving application state untouched, use cy.screenshot() with its selector-based blackout option. If the banner is controlled by a backend response, intercept that real request and return a test response. In every case, wait for a deterministic application signal before capturing.

Choose the result you actually need

“Remove” can mean two different things in a screenshot test. A functional test should prove that the application behaves as it does for a visitor who has already consented. A visual-regression test may only need an unobstructed image. Those goals require different techniques.

Goal Method What the screenshot represents Important limitation
Show a saved, post-consent state Set the application’s actual consent cookie before visiting The page as a visitor with recorded consent would see it You must know the cookie name, accepted value, scope and whether the server or client reads it
Produce a clean image without changing state Use blackout with the banner selector The original page with selected pixels covered in the image It does not remove the banner from the live page and is not available for runner captures
Reproduce a server-defined consent state Intercept the real consent-state request The UI produced by the stubbed response A browser-cached response may bypass network interception

Pick one approach per test based on state fidelity, test purpose and capture mode rather than trying to hide every banner with a single global trick.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Method 1: set the real consent cookie before visiting

Use this when the screenshot should depict a visitor who has already made a consent choice. Cypress documents setting a known cookie in a beforeEach hook with cy.setCookie() (Cypress FAQ).

Basic example

describe('page without a consent banner', () => {
  beforeEach(() => {
    cy.setCookie('cookieConsent', 'accepted')
    cy.visit('/')
  })

  it('captures the post-consent page', () => {
    cy.get('[data-testid="page-ready"]').should('be.visible')
    cy.screenshot('page-after-consent')
  })
})

cookieConsent, accepted, [data-testid="page-ready"] and the root URL are illustrative. Replace them with values from your application. Inspect the browser’s cookies after accepting the banner manually, or check the application’s documented contract, to identify the exact name and value. Some applications also require a particular path, domain, expiration or secure setting; match those attributes when using the extended cy.setCookie() options.

Set the cookie on the correct origin

A cookie belongs to a domain and path. Visit the application’s origin before setting a cookie if Cypress cannot determine the target domain, and ensure that the cookie is not being set for a different subdomain than the page under test. If the consent decision is stored in local storage, session storage or an application-specific API instead of a cookie, seed that mechanism rather than inventing a cookie.

Verify that the application consumed the state

Setting a cookie does not guarantee that the page has read it. Assert a stable result, such as a page-ready marker, the absence of the banner, or an application attribute that means consent has been applied. Prefer an assertion tied to rendering or a completed request over a fixed sleep.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
cy.setCookie('cookieConsent', 'accepted')
cy.visit('/checkout')
cy.get('body').should('not.have.attr', 'data-consent-pending')
cy.get('[data-testid="page-ready"]').should('be.visible')
cy.screenshot('checkout-after-consent')

If your application intentionally displays different content for different consent categories, seed the complete value that the production code expects. A partial or malformed value can leave the banner visible while making the test appear flaky.

Method 2: blackout the banner in the screenshot

Use blackout when the test’s purpose is a clean visual artifact, not proof that consent works. Cypress accepts an array of CSS selectors in the blackout option of cy.screenshot() (Cypress screenshot API).

#1 Best Overall
Capture Card, 4K HDMI Video Capture Card, Game Capture Card, 1080P 60FPS Video Capture Device, HDMI to USB 3.0 Capture Card for Streaming, Work with Camera/Xbox/PS4/PS5/PC/OBS
  • 【1080P HD High Quality】Capture resolution up to 1080p for video source and it is ideal for all HDMI devices such as PS4, PS3, Xbox One, Xbox 360, Wii U, DVDs, DSLR, Camera, Security Camera and set top box. Note: Video input supports 4K30/60Hz and 1080p120/144Hz. Does not support 4K120Hz/144Hz. Output supports up to 2K30Hz.
  • 【Plug and Play】No driver or external power supply required, true PnP. Once plugged in, the device is identified automatically as a webcam. Detect input and adjust output automatically. Won't occupy CPU, optional audio capture. No freeze with correct setting.
  • 【Compatible with Multiple Systems】suitable for Windows and Mac OS. High speed USB 3.0 technology and superior low latency technology makes it easier for you to transmit live streaming to Twitch, Youtube, Facebook, Twitter, OBS, Potplayer and VLC.
  • 【HDMI LOOP-OUT】Based on the high-speed USB 3.0 technology, it can capture one single channel HD HDMI video signal. There is no delay when you are playing game live.
  • 【Support Mic-in for Commentary】Rybozen capture card has microphone input and you can use it to add external commentary when playing a game. Please note: it only accepts 3.5mm TRS standard microphone headset.
cy.visit('/')
cy.get('[data-testid="page-ready"]').should('be.visible')
cy.screenshot('page-without-consent-banner', {
  blackout: ['[data-testid="cookie-banner"]'],
})

What blackout does—and does not do

  • It changes the captured pixels for the matching element.
  • It does not dismiss the banner, set consent, or alter the application’s runtime state.
  • The selector must match the element at capture time; if the banner is inside an iframe or shadow root, a normal document selector may not reach it.
  • Cypress specifies that blackout does not apply to runner captures. Use a supported screenshot capture mode for the image you intend to publish or compare.

Choose a stable selector such as a data attribute rather than a generated class. If the banner moves or changes size between runs, blackout can still produce inconsistent surrounding pixels; wait for the final layout before taking the screenshot.

Method 3: intercept the request that controls consent state

Some applications fetch a consent configuration or preference from the server. In that case, intercept the actual request before navigation and return a fixture representing the state you want. Cypress’s cy.intercept() command supports spying and stubbing (Cypress intercept API).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
cy.intercept('GET', '/the-real-consent-config-route', {
  fixture: 'consent/accepted.json',
}).as('consentConfig')

cy.visit('/')
cy.wait('@consentConfig')
cy.get('[data-testid="page-ready"]').should('be.visible')
cy.screenshot('page-after-stubbed-consent')

The route and fixture shape above are placeholders. Use the URL, method and response fields defined by your application; do not guess an endpoint. If the app sends a request only after a script runs, register the intercept before cy.visit() so the request cannot win a race.

Cache can make an intercept appear broken

Cypress notes that a response served from the browser cache does not reach the network layer and therefore cannot be intercepted there. If your alias never resolves, inspect the browser’s network activity and cache headers. Disable or vary caching in the test environment, change the request so it is genuinely made, or seed the state through the cookie or storage mechanism instead.

Rank #2
Guermok Video Capture Card, 4K USB3.0 HDMI to USB C, 1080P 60FPS & 2K 30FPS
  • 【1080P 60FPS Video Capture Card】 This HDMI game capture card is based on USB3.0 high speed transmission port, input resolution up to 4K@30HZ, output resolution up to 2K@30Hz or 1920×1080@60Hz. Type c and USB interface can meet most of the devices in daily life. Easily meet the online capture, real-time recording, online meetings, live gaming and other functions, so you have a better visual enjoyment. Note: For capture use only; requires capture software to function and is not intended for direct screen casting to a monitor or TV
  • 【Ultra Low Latency Screen Sharing】 HDMI capture card is made of good quality aluminum alloy with strong heat dissipation, allowing you to enjoy ultra low latency while live gaming or video recording or live streaming, avoiding blue screens and lag. This HDMI to USBC capture card supports easy recording of good quality audio or HD video and transferring it to your computer or streaming platform, allowing you to record 60 fps HD video directly on your hard drive and real-time preview
  • 【Plug and Play, Easy to Carry】 This HDMI 1080P video capture card does not require any additional drivers or external power supply, just plug and play for fast capture. The capture card is small and lightweight, so you can put it in your bag for emergencies, making it very portable for outdoor live streaming. It's also a great way to share content in game recording, video conference, video recorder and online teaching
  • 【Wide Compatibility USB Capture Card】 Easily streams to Facebook, Youtube or Twitch. With the connection, this HDMI to USB C/3.0 video capture devices can be working on several Operating Systems and various software: Windows 7/ 8/ 10, Mac OS or above, Linux, Android, Laptop, Xbox One, PS3/PS4/PS5, Camera, DVDs, Set Top Box, Webcame, DSLR, Switch/Switch 2, TV BOX, HDTV, Potplayer/VLC, ZOOM, OBS Studio etc.
  • 【Package Content & Note】 1x HD Audio Capture Card , 1x USB 3.0 to USB C Adapter (A-side 3.0, B-side 2.0), 1x user manual. Please note that you need to restart the OBS Studio software after the audio setup is complete, otherwise it will result in no sound output. When using an adapter, if the device is recognized as USB 2.0, try using the other side with the USB-C port. Simply flip the capture card and reconnect it to be recognized as USB 3.0

Synchronize on application state, not a timer

A screenshot taken while the consent script is still loading can capture a banner that would disappear a moment later. Cypress recommends interacting after elements are actionable and using observable application signals (Interacting with elements). Use one or more of these signals:

  • Wait for the aliased consent request with cy.wait().
  • Assert a readiness marker such as [data-testid="page-ready"].
  • Assert that the banner is not visible after seeding consent.
  • Check an application-set class or attribute that denotes the settled state.
  • Wait for images, fonts or other layout-critical content that affects the screenshot.

A fixed cy.wait(2000) can pass on one machine and fail on another. It also hides whether the page is genuinely ready. Cypress’s conditional-testing guidance explains why branching on unstable DOM state is fragile and why deterministic setup is preferable (Conditional testing in Cypress).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Reusable Cypress patterns

Post-consent visual regression

beforeEach(() => {
  cy.setCookie('YOUR_REAL_CONSENT_COOKIE', 'YOUR_ACCEPTED_VALUE')
  cy.visit('/pricing')
  cy.get('[data-testid="page-ready"]').should('be.visible')
})

it('matches the pricing baseline', () => {
  cy.get('[data-testid="cookie-banner"]').should('not.be.visible')
  cy.screenshot('pricing-post-consent')
})

Visual-only cleanup

cy.visit('/pricing')
cy.get('[data-testid="page-ready"]').should('be.visible')
cy.screenshot('pricing-clean-artifact', {
  blackout: ['[data-testid="cookie-banner"]'],
})

Consent behavior plus clean capture

Keep these concerns in separate tests. First test that the banner appears, accepts a choice and disappears. In a second test, seed the accepted state and capture the resulting page. This prevents a visual test from accidentally becoming the only coverage for consent functionality.

Troubleshooting common failures

The banner is still visible after cy.setCookie()

  • Wrong name or value: compare the cookie created by a real acceptance flow with the value in the test.
  • Wrong domain or path: set the cookie for the same origin and path that serves the page.
  • Client state is also required: seed local storage or the application API if the cookie is only one part of the decision.
  • Consent is read before navigation: set the cookie before cy.visit(), not after.
  • Banner is rendered by another origin: verify which frame or subdomain owns it and use the application’s supported cross-origin strategy.

Blackout has no effect

  • Confirm the selector matches an element at screenshot time and is not scoped to a component that has not rendered.
  • Make sure you are not taking a runner capture, because Cypress documents blackout as unsupported there.
  • Check whether the banner is inside an iframe or shadow DOM; target it using the application’s test hooks or capture strategy.
  • Remember that blackout hides pixels only. The banner can remain interactive and visible to other assertions.

cy.wait('@consentConfig') times out

  • Check the HTTP method, URL pattern and whether the request occurs at all.
  • Register cy.intercept() before cy.visit().
  • Investigate browser cache, which can prevent the request from reaching the interception layer.
  • Do not stub a guessed endpoint; trace the request that actually determines banner state.

Screenshots are flaky even though the banner is gone

  • Wait for a page-ready marker and any request that controls layout.
  • Ensure fonts, lazy images and animations have settled in the test environment.
  • Use stable selectors and a consistent viewport.
  • Capture after the application’s final state rather than after an arbitrary delay.

Performance, isolation and maintenance

Cookie seeding is usually the fastest option because it avoids opening and interacting with the consent UI. It also gives the highest state fidelity when the cookie is the application’s real source of truth. Blackout is simple and isolated, but it can conceal a regression in banner placement or behavior. Network stubbing is powerful for server-driven flows, yet it requires maintenance whenever the API contract changes and must account for caching.

Keep consent setup in a helper or custom command only after the underlying contract is understood. Name screenshots according to the state they represent, such as post-consent or blackout-banner, so reviewers do not mistake a pixel treatment for functional consent coverage. Keep the acceptance test and the clean visual test independent, and clear cookies between tests when the suite requires a fresh visitor.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

For automated image capture outside Cypress, ScreenshotNeo provides a single request to return a PNG, JPEG, WebP or PDF. It accepts the consent banner like a visitor and removes more than 60 known consent platforms, newsletter popups and chat widgets before capture; each cleanup step can be disabled. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits cost nothing, and the response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP server provides take_screenshot, get_page_info and capture_pdf tools for Claude, Cursor and other MCP clients. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

One-call cURL example

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for output formats, cleanup controls, readiness options and the other capture parameters.

To start with 1,000 free screenshots a month and no card, create a ScreenshotNeo account.

Rank #3
Sale
Elgato 4K S Capture Card for PS5, Xbox Series X/S, Switch 2
  • 4K60 Capture: Record in cinematic quality with crisp detail and vivid colors
  • HFR Support: Play and capture in 1440p120 or 1080p240
  • HDR10 Support: Capture brilliant HDR content with tone mapping on Windows
  • Cross-Platform Compatible: Works with PS5, Xbox Series X/S, Switch 2, and more
  • Analog Audio In: Capture in-game chat or commentary with 3.5mm input

FAQ

Should I hide the banner or test accepting it?

Test acceptance when consent behavior matters; use blackout only when the deliverable is a clean image and state fidelity is not part of that test.

Can I intercept any cookie-banner request?

Only intercept a request that genuinely controls the application’s consent state. A guessed route or cached response will not produce a reliable test.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why avoid conditional checks such as “if the banner exists”?

Unstable DOM timing makes such branches nondeterministic. Deterministic setup through cookies, storage or a real intercepted response is easier to reason about.

Rank #4
Capture Card 4K HDMI Video Streaming to USB 3.0 1080P 60FPS Capture Device
  • High-Quality Video Capture, 4K HDMI Capture Card Ready: Capture smooth and vibrant video with this 4K HDMI capture card, engineered for gamers and content creators who demand crisp 1080P 60FPS video quality. Whether you're streaming to Twitch or recording gameplay for YouTube, your footage will look professional and detailed
  • Plug-and-Play USB Capture Card, No Drivers Needed: Designed as a USB capture card for streaming, this device works instantly out of the box, just plug into your PC or laptop and start capturing. Fully compatible with popular software like OBS Studio, Streamlabs, and XSplit, making setup quick and stress-free for beginners and pros alike
  • Universal Compatibility PS5, Xbox, Switch & More: Stream or record gameplay from virtually any HDMI-enabled device including Nintendo Switch, PS5, Xbox Series X, DSLR cameras, and PCs. The video capture card for gaming supports seamless passthrough so you can play without lag while your audience watches every frame in real time
  • Low-Latency Performance for Smooth Streaming: This capture card for streaming minimizes delay between gameplay and broadcast, so you get reliable, low-latency capture that works well for competitive gaming, live broadcasts, and podcast sessions. Suitable for those building their channel with high-quality, engaging content
  • Compact & Portable Design for Content Creators: Lightweight and portable, this USB 3.0 capture card works well for creators who travel or switch gaming setups often. Throw it in your bag and stream or record wherever you are, at home, events, LAN parties, streaming or studio sessions

Frequently Asked Questions

Does Cypress delete the cookie after each test?

Cookie isolation depends on your Cypress test setup and origin handling. Explicitly seed or clear consent state when a test requires a known visitor condition.

Can blackout prove that consent was stored?

No. Blackout changes screenshot pixels only; it does not exercise or verify the consent mechanism.

What if the consent banner is loaded from an iframe?

Identify the owning origin and use the application’s supported cross-origin or component strategy; a top-level selector may not match content inside the frame.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.