To test logout in Cypress, start from a known authenticated state, trigger the application’s actual logout action, then verify the signed-out experience and the session effect your app promises. Use a UI test for the user journey; use cy.request() as a complementary check of the server endpoint. Neither a cleared app cookie nor a redirect alone proves that an identity provider’s wider single-sign-on session has ended.
Choose what “logged out” means for your app
Before writing assertions, define the contract being tested. Depending on the application, logout may clear an authentication cookie, remove client-side state, redirect to a public route, or cause protected requests to be rejected. Assert the effects that apply to your app rather than assuming a universal cookie name, storage key, endpoint, or destination.
- Application logout: the current app no longer treats the browser as authenticated.
- Identity-provider logout: the external provider session is ended, potentially affecting other applications that use it.
These are distinct scopes. Auth0 documents logout behavior that can span applications, so an assertion that an app is signed out should not be presented as proof that provider-wide SSO has ended: Auth0 logout documentation.
Prepare a reliable authenticated state
If the login form is not the subject of the test, avoid repeating interactive login setup in every test. Cypress’s cy.session() can cache and restore cookies, local storage, and session storage. Use a reusable custom command or helper to establish the session and validate it by visiting a protected route or calling an authenticated API. If validation fails, Cypress reruns the setup callback. See Cypress cy.session() documentation.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
With test isolation enabled, Cypress clears the page and session data according to the session lifecycle. After setting up or restoring a session, explicitly call cy.visit() for the page the test needs; session caching is setup convenience, not a logout test.
Test the logout control through the UI
A UI logout test verifies the action a user takes and the client-side transitions that follow it. The selector, route, and cookie below are examples: replace them with the application’s actual control and contract.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
// cypress/e2e/logout.cy.js
describe('logout', () => {
beforeEach(() => {
cy.loginByApi(); // Your helper: establish and validate an authenticated session.
cy.visit('/account');
});
it('signs the user out through the account menu', () => {
cy.get('[data-testid="logout"]').click();
cy.location('pathname').should('eq', '/');
cy.get('[data-testid="login-link"]').should('be.visible');
cy.getCookie('auth_token').should('not.exist');
// Check that a protected resource is no longer available to this browser.
cy.request({
url: '/api/me',
failOnStatusCode: false,
}).its('status').should('be.oneOf', [401, 403]);
});
});
The example assumes a helper named cy.loginByApi(), a logout button with the stated test ID, a home-page redirect, a cookie named auth_token, and a protected endpoint returning 401 or 403 after logout. Those details are app-specific; keep only assertions that match the documented behavior of your own app. Cypress’s custom-command examples also demonstrate checking that an authentication cookie no longer exists after a UI logout: Cypress custom commands.
Test the logout endpoint with cy.request()
When the server-side logout contract matters, call the endpoint directly and assert its response and resulting browser state. Cypress documents that cy.request() shares cookies with the browser, so a response that clears a cookie updates the browser’s cookie jar. The API test is useful for endpoint behavior but does not click the logout control or exercise client-side transitions: Cypress network requests guide.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
it('clears the browser session through the logout endpoint', () => {
cy.loginByApi();
cy.visit('/account');
cy.request({
method: 'POST',
url: '/api/logout',
failOnStatusCode: false,
}).then((response) => {
expect(response.status).to.be.oneOf([200, 204]);
});
cy.getCookie('auth_token').should('not.exist');
cy.visit('/account');
cy.get('[data-testid="login-link"]').should('be.visible');
});
Adapt the method, path, acceptable status codes, cookie assertion, and post-logout route to the app. For example, some APIs use a different HTTP method or redirect-based logout; the sample does not establish those details. Combine this endpoint test with the UI test when both the server contract and user interaction are in scope.
Test identity-provider logout separately when needed
For federated authentication, decide whether the requirement is to end only the application’s local session or also the identity-provider session. Cypress’s Auth0 guide recommends using a test tenant or test API and a dedicated test user, with the app’s callback, web-origin, and logout URLs configured. It demonstrates both UI and programmatic authentication and uses cy.session() to reuse login state: Cypress Auth0 authentication guide.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Provider-specific setup matters: Cypress also documents social authentication and Amazon Cognito examples. Follow the provider’s own logout contract and assert only the scope you configured. A local redirect or cleared application cookie is not evidence that another relying application will require sign-in.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Use cy.session() for setup, not logout verification
cy.session() restores saved session data; it does not sign the user out or demonstrate that logout works. A reliable pattern is to establish the session before the test, explicitly load the relevant page, execute logout, and then verify the app’s signed-out contract. Cypress records that cy.session() became available by default in version 12.0.0, when experimentalSessionAndOrigin was removed: Cypress session command history.
Free tools Windows power users keep installed
One-click scans. No signup required.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Common failures and fixes
- The cookie assertion fails after endpoint logout: check that the request uses the correct method and endpoint, that the server sends a cookie-clearing response for the same cookie scope, and that the browser had the expected cookie before the request.
- The test is already signed out after session setup: validate the restored state against a protected route or authenticated API, then visit the page explicitly after
cy.session(). - The UI assertion passes but protected requests still work: add an assertion against a protected resource; a changed page or redirect alone may not establish that the server rejects the old session.
- The API test passes but the logout button is broken: add a separate UI test. A direct endpoint request bypasses the control and client-side transitions.
- Other apps remain signed in: determine whether the requirement includes identity-provider logout. Application-local sign-out and provider-wide SSO logout are different contracts.
Or skip the browser setup
For a screenshot of a page in a logout flow, ScreenshotNeo provides a one-call screenshot API; it complements Cypress assertions rather than replacing them. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000. See ScreenshotNeo API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Get ScreenshotNeo and sign up free for 1,000 screenshots a month, with no card required.
Frequently Asked Questions
Can I test logout with cy.request()?
Yes. It can call the logout endpoint and test the server response; it does not exercise the application’s logout control.
Does cy.session() log the user out?
No. It caches and restores session data for test setup; logout must be tested through the app’s logout behavior.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesQuick Recap
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.

