QA Interview Hub · Knowledge base · Quizzes · Українська

Cypress

State, sessions, isolation

login, cookies, several domains

How does Cypress isolate tests from each other?

Since Cypress 12 the testIsolation option is on by default and clears the browser before every test. Cypress navigates to about:blank and clears cookies, localStorage and sessionStorage, so a test does not depend on run order and a retry starts clean. Data on the server stays, so each test prepares its own state and cleans up or uniquifies data. Turning isolation off is an exception for a long scenario.

Cypress · Sessions and isolation

Test B works only if test A ran before it. Why is that not allowed and what does Cypress do?

Test A logs a user in and opens the dashboard, test B just calls cy.get('[data-cy=balance]') and expects everything to be ready. Run on its own or with .only, B fails. To prevent that, Cypress clears the browser before every test. The lesson covers what exactly is cleared, what is not, and what follows for tests.

How it works and why. Since Cypress 12 the testIsolation option is on by default. Before every test Cypress navigates to about:blank and also clears cookies, localStorage and sessionStorage for every origin. The goal is simple: a test does not depend on the run order, it can be run on its own, and a retry after a failure starts from a clean state. The price: every test prepares its own state, that is, opens the page and, if needed, logs in.

What is cleared between tests

Page → about:blankthe old DOM and app state are gonecookies, localStorage, sessionStoragefor every originServer and database dataCypress does not touch them
Figure 1. Browser state is cleared, not the application data on the server.

Example: a test that lives on the leftovers of another.

Order-dependent

Login only in the first test

The second test knows nothing about the login: after cookies are cleared it is redirected to the sign-in page and cy.get will not find the balance.

Independent

Every test prepares its own state

Shared preparation in beforeEach: login (preferably through cy.session) and cy.visit. The test can be run on its own.

describe('Dashboard', () => {
  beforeEach(() => {
    cy.login('user'); // cy.session inside
    cy.visit('/dashboard');
  });

  it('shows the balance', () => {
    cy.get('[data-cy=balance]').should('be.visible');
  });

  it('opens the transaction history', () => {
    cy.contains('a', 'History').click();
    cy.url().should('include', '/history');
  });
});

Here no test depends on its neighbour: the hook prepares the same start and every it checks its own thing. The cy.login command is described in the lesson about cy.session.

Limits and alternatives. The clearing concerns the browser. Data a test created on the server (an order, a user in the database) stays, so it needs separate cleanup or unique data. Isolation can be switched off: testIsolation: false in the config or for a single describe, for example describe('flow', { testIsolation: false }, …). Then the page and state carry over between tests, which speeds up a long scenario, but tests become order-dependent and a retry does not start from a clean state. It is an exception, not a habit.

And in Playwright:

Isolation out of the box is different: every test gets a new BrowserContext, a separate profile like incognito. Nothing is erased, the context is created anew in milliseconds.

Common mistakes.

  • Logging in during one test and trying to “reuse” it in the next: after cookies are cleared the user is logged out.
  • Relying on data created by a previous test: it stayed on the server, but the run order is not guaranteed.
  • Turning testIsolation off everywhere for speed: tests become brittle and cannot be run alone.
  • Assuming the clearing also cleans the database: Cypress does not reset application data.

Check yourself

Test A creates an order through the UI, test B checks that the list has exactly one order, and is green. Is that reliable?

Answer

No. Isolation clears the browser, but the order from A stayed on the server, so B passes only by accident of order. Alone, B would fail. Data must be prepared in the test itself or cleaned up.

When might testIsolation: false be needed and what is the price?

Answer

For a long end-to-end scenario split into steps, when you do not want to reopen the page each time. The price: tests depend on order, one failure breaks the next ones and a retry does not restore a clean state.

In an interview. Junior: Since version 12 Cypress clears the page, cookies, localStorage and sessionStorage before every test: that is testIsolation. So tests are independent and each prepares its own state. Middle/Senior: I explain the difference from Playwright like this: there is a new context per test, here a cleanup in the same browser. The cleanup does not touch the server, so I isolate test data separately and move login into cy.session so preparing state does not cost a full sign-in every time.

What is cy.session and how do you avoid logging in in every test?

cy.session runs the login once, saves cookies, localStorage and sessionStorage, and restores them in later tests. The data is stored under the id key and setup is not called again. The validate option checks that the restored session is still alive, otherwise setup runs again. One id should match one user or role. After cy.session the page is blank, so the test calls cy.visit itself.

Cypress · Sessions and isolation

There are fifty tests and each logs in. The suite is slow. How do you log in once without breaking isolation?

Test isolation requires every test to have a logged-in user, but a full login fifty times costs time and hurts stability. cy.session logs in once, saves the result and restores it in every following test. The lesson explains how it works, when a session counts as alive and what goes into it.

How it works and why. cy.session(id, setup, options) stores, under the key id, the cookies, localStorage and sessionStorage left after setup. In later tests with the same id Cypress clears the page, restores the saved data and does not call setup. The validate option checks that the restored session is still valid: if a command in it fails or the returned chain or Promise yields false (a plain return false does not count), Cypress runs setup again, and if validate still fails after that, the test fails. cacheAcrossSpecs: true shares the cache between spec files. After cy.session the page is blank: the test itself must navigate to the needed address.

The life of a session

1st call: setuplogin, saving cookies and storagesLater calls: restoreno login; then validatevalidate failed: setup againthe session expired, log in anew
Figure 1. The login happens once, then the session is only restored and checked.

Example: a login command with a session.

Cypress.Commands.add('login', (role = 'user') => {
  cy.session(
    role, // id: a separate cache per role
    () => {
      cy.env([role + '_email', role + '_password']).then((env) => {
        cy.request('POST', '/api/auth/login', {
          email: env[role + '_email'],
          password: env[role + '_password'],
        });
      });
      // the cookie from the cy.request response lands in the browser
    },
    {
      validate() {
        cy.request('/api/me').its('status').should('eq', 200);
      },
      cacheAcrossSpecs: true,
    },
  );
});

beforeEach(() => {
  cy.login('admin');
  cy.visit('/dashboard');
});

The login goes through cy.request, with no form, and Cypress puts the Set-Cookie from the response into the browser. Credentials come from cy.env, not from the test code. If the app keeps a token in localStorage, write it in setup with window.localStorage.setItem and the session will save it just the same.

Limits and alternatives. cy.session stores only cookies, localStorage and sessionStorage. It knows nothing about the server side: if the server revoked a token or the session expired, only validate helps, so without it tests fail in random places. One id must stand for one user: if two roles share a key, the wrong session is restored. If login goes through an external provider, setup may contain cy.origin.

And in Playwright:

The analogue is storageState: a setup project logs in and saves cookies and localStorage to JSON, other projects load the file with the storageState option, and dependencies makes setup run before them. One file per role, and a single test can hold two contexts with different roles at once.

Common mistakes.

  • Skipping validate: the token expired and the test fails not at the login but somewhere later.
  • Forgetting cy.visit after cy.session: the page is blank and cy.get finds nothing.
  • One id for different users: a test for the “admin” role gets the “user” session.
  • Assuming cy.session saves data on the server: it is only a snapshot of browser state.

Check yourself

What happens when, during a session restore, validate gets a 401?

Answer

Cypress treats the session as invalid and runs setup again, that is, logs in anew. If validate fails again after that, the test fails with an error: the login itself is broken.

A test calls cy.login('user') in beforeEach and then cy.get('[data-cy=balance]') without cy.visit and fails. Why?

Answer

After cy.session the page is cleared to about:blank. The session restored cookies but did not open anything. You need cy.visit('/dashboard').

In an interview. Junior: cy.session does this: it runs the login once, saves cookies and storages and restores them in later tests. validate checks that the session is still alive. Middle/Senior: I do the login inside setup through the API. A separate id per role gives quick user switching, and cacheAcrossSpecs shares the session between files. Without validate an expired session causes flaky failures, so it is mandatory.

How do you work with several origins through cy.origin?

cy.origin runs a callback in the context of another origin, because the same-origin policy stops a test from driving a page of a foreign origin directly. Commands for the foreign page go inside the block, and outside variables do not reach it: they are passed through args and must be serialisable. In practice an external login is usually bypassed through the API and cy.session, and cy.origin is kept for one test.

Cypress · Sessions and isolation

After clicking “Sign in with SSO” the page changed its origin and the next command fails with an origin error. What now?

A login through an external provider starts on the app’s site, goes to the provider’s form and comes back. Plain cy.get commands on the provider’s page raise an error although the element is visible. For such scenarios there is cy.origin. The lesson explains why, how to pass data into the block and where it is better not to use it.

How it works and why. The browser forbids a page of one origin to read the DOM of a page of another origin (the same-origin policy). A Cypress test runs together with the page of its own origin, so after navigating to another origin it cannot drive the new page directly. cy.origin(url, options, callback) runs the callback in the context of the other origin: Cypress attaches to that page and commands inside the block act there. Since Cypress 14 “another origin” means any other one, including a subdomain, not only a different top-level domain. The callback runs in another context, so outer variables do not reach it: pass data explicitly through args, and it must be serialisable (plain values, objects, arrays, but not functions).

The path of a test between origins

Primary origin: the appcy.visit, click “Sign in with SSO”Another origin: the providercommands only inside cy.originBack to the primary origincy.url(), cy.get work normally again
Figure 1. Commands for the foreign origin sit only inside the cy.origin block.

Reading the error: a command on a foreign origin

1CypressError: The command was expected to run against origin http://localhost:3000 but 2the application is at origin https://auth.provider.com.
  1. What: the command ran in the context of the origin the test started on. Cypress expects the app to still be there.
  2. Why: after the “Sign in with SSO” click the app is on the provider origin. The element may be on screen, but the message is not about it.

What to do

Wrap the provider commands in cy.origin('https://auth.provider.com', { args }, callback) and pass the data through args.

Figure 2. The real error text (shortened): the numbers lead to the explanations.

Example: SSO login.

const user = { email: 'qa@test.com', password: 'secret' };

cy.visit('/');
cy.get('[data-cy=sso-login]').click();

// commands for the provider: only inside cy.origin
cy.origin(
  'https://auth.provider.com',
  { args: user },
  ({ email, password }) => {
    cy.get('#email').type(email);
    cy.get('#password').type(password, { log: false });
    cy.get('button[type=submit]').click();
  },
);

// back in the primary origin
cy.url().should('include', '/dashboard');

If email and password were just variables nearby, the callback would not see them: they do not exist in it. That is why they travel through args and arrive as a parameter. After the block the provider redirects to the app and the following commands work in the primary origin again.

Limits and alternatives. Custom commands and imports of an outer file do not work inside cy.origin: they are attached inside the callback through Cypress.require(), which needs the experimental experimentalOriginDependencies option turned on in the config. The block should not be used in every test: it is slow, and the provider’s page (captcha, MFA, markup changes) is not under your control. A practical approach: one test checks the SSO flow itself through cy.origin, and the rest log in directly through the API and cy.session.

And in Playwright:

There is no such limit: the test simply navigates to another origin and all commands work as usual. Several tabs and contexts within one test are also normal.

Common mistakes.

  • Using an outer variable in the callback: it is undefined because the block runs in another context.
  • Calling cy.get for the foreign origin outside cy.origin: Cypress complains about the origin, not about a missing element.
  • Passing functions or class instances in args: they are not serialisable.
  • Going through cy.origin for every page of the app: slow and dependent on a page you do not own.

Check yourself

A test declares const token = 'abc' and cy.origin(...) uses token without args. What happens?

Answer

The callback runs in another context, so token does not exist in it and an error occurs. The value must be passed as { args: { token } } and received as a parameter.

Is cy.origin needed to go from app.example.com to auth.example.com?

Answer

Yes. Since Cypress 14 a subdomain counts as another origin, so commands on the auth.example.com page go inside cy.origin.

In an interview. Junior: For scenarios with another origin, such as an SSO login, there is cy.origin: commands for the foreign origin are written inside this block. Outer variables do not get there, they are passed through args. Middle/Senior: In practice I bypass the external login through the API and cy.session more often and keep cy.origin for one test that checks the flow itself. That way the suite does not depend on a foreign page with captcha or MFA, and the SSO flow is still covered.

Why is programmatic login better than login through the UI?

Programmatic login is better because it is faster than the form and does not depend on it: for most tests login is only a precondition. The cy.request call repeats the form's request and Cypress puts Set-Cookie from the response into the browser, so a broken form does not fail the whole suite. The result is cached with cy.session, and one separate test checks the form itself.

Cypress · Sessions and isolation

The “Sign in” button broke and a hundred tests fell that checked something else entirely. How do you avoid that?

A suite of a hundred tests, each starting with a login through the form. One morning the selector of the password field changed on the form and the whole suite is red although the balance, the history and the profile work. The lesson is about why login as preparation is better done programmatically, with the form checked separately.

How it works and why. A test checks one thing and the login is only a precondition for it. If the precondition goes through the UI, any broken form, slow animation or markup change fails all tests, and the report does not make clear what exactly broke. A programmatic login sends the same request the form sends, but directly: cy.request sends a POST to the sign-in endpoint and Cypress puts the Set-Cookie of the response into the browser. Then cy.session caches the result and later tests do not repeat the request.

Two ways to prepare state

In every test

Login through the form

Every test opens the sign-in page, types the fields and waits for the redirect. A test that checks the balance goes red when the “Sign in” button breaks.

Once

Login through the API and cy.session

The signed-in state is prepared by a request without the UI and restored from the cache. One separate test checks the form.

Figure 1. Preparation through the API does not depend on the form, and the form has its own test.

Example: from the form to a request.

// before: in every beforeEach
cy.visit('/login');
cy.get('[data-cy=email]').type('qa@example.com');
cy.get('[data-cy=password]').type('secret');
cy.contains('button', 'Sign in').click();

// after: a request instead of the form
cy.request('POST', '/api/auth/login', {
  email: 'qa@example.com',
  password: 'secret',
});
cy.visit('/dashboard');

The second variant does not open the sign-in page, does not wait for a redirect and does not depend on the form markup. In a real suite it is wrapped in cy.session and the password comes from cy.env rather than the test file. The form itself is checked by one test: fields, validation, the error for a wrong password and the redirect.

Example: a token in localStorage and the session cache. If the app keeps sign-in not in a cookie but in a token, the cy.request response changes nothing in the browser by itself: the token has to be written to the storage by hand. It is convenient to do it in the session setup, so the entry is restored together with the session, while validate checks that the token is still valid.

Cypress.Commands.add('loginByApi', (email, password) => {
  cy.session(
    ['api', email],
    () => {
      cy.request('POST', '/api/auth/login', { email, password })
        .its('body.token')
        .then((token) => {
          cy.window().then((win) => {
            win.localStorage.setItem('token', token);
          });
        });
    },
    {
      validate() {
        // a 401 on /api/me means the token has expired
        cy.request('/api/me');
      },
    },
  );
});

beforeEach(() => {
  cy.env(['PASSWORD']).then(({ PASSWORD }) => {
    cy.loginByApi('qa@example.com', PASSWORD);
  });
  cy.visit('/dashboard');
});

Here the session key contains the email, so different users do not share the cache. The token in localStorage ends up in the saved session because cy.session stores localStorage together with cookies. If /api/me returns 401, cy.request fails, validate fails with it and Cypress runs setup again. The password in the example comes from cy.env: Cypress.env() was removed in Cypress 16.

Limits and alternatives. A programmatic login needs an endpoint that can be called from a test. When sign-in goes only through an external provider with a captcha or MFA, teams often create a test endpoint or a test user with a simpler sign-in; the last resort is cy.origin in one test. Test credentials must be separate and not from production. Also an API login bypasses the form, so if the form breaks only its own test will notice: that test must not be skipped.

And in Playwright:

The approach is the same: login through the API, the result is saved in storageState and one separate test checks the UI login.

Common mistakes.

  • A login through the form in every beforeEach: the suite is slow and one broken form turns everything red.
  • A programmatic login without a separate test of the form: nobody will notice a broken form.
  • Passwords in the test text or the repository: keep them in environment variables or cy.env.
  • A login through cy.request to a different origin than the app: the cookie lands where the app does not expect it.

Check yourself

All tests log in through the API, the sign-in form broke and the suite is green. Is that good?

Answer

No, it is a gap. An API login bypasses the form, so only a separate UI sign-in test would notice the break. That test must stay: it checks the form, validation and the redirect.

Why is the browser already logged in after cy.request('POST', '/api/auth/login', …)?

Answer

Cypress applies the cookies from the cy.request response to the browser. If sign-in relies on a cookie, the next cy.visit opens the page of a logged-in user at once. A token in localStorage must be written separately.

In an interview. Junior: If every test logs in through the form it is slow, and a broken form fails the whole suite although the tests check something else. So I log in through the API and cache the session. Middle/Senior: I check the sign-in form with one separate test: fields, validation, the error and the redirect. I take credentials from cy.env, agree a test sign-in for an external provider and keep cy.origin for a single test.

Custom commands and cy.session

A custom command gathers a repeated action such as login in one place, so a changed endpoint needs one edit. Cypress.Commands.add registers it in the support file, and in TypeScript it is declared in Chainable. Inside, cy.session is called, with a key built from the role and environment so caches do not mix. The command is kept short and free of assertions, with more complex logic moved into module functions.

Cypress · Sessions and isolation

The login is copied into thirty tests and the password changed. How do you move it into one command?

In a suite login, data creation and form steps repeat in many tests. When the endpoint or the way of authorisation changes, you have to edit everywhere. A custom command gathers a repeated action in one place, and together with cy.session it gives one fast sign-in for all tests. The lesson covers how to write it, type it and where to be careful.

How it works and why. Cypress.Commands.add(name, fn) registers a command in the support file (usually cypress/support/commands.ts, imported by e2e.ts). After that cy.name() is available in every spec. Inside the command you can call any Cypress command, including cy.session. The session key then consists of what tells users apart: the role and, if needed, the environment. For TypeScript the command is declared in the Chainable interface, otherwise the compiler will not know about cy.login.

The layers of sign-in

Test: cy.login("admin")one readable commandCommand: cy.session(id, …)cache by id: role, environmentsetup: cy.request to the APIruns only when there is no cache
Figure 1. The test sees one command and the login details are hidden two layers below.

Example: a typed login command.

// cypress/support/commands.ts
declare global {
  namespace Cypress {
    interface Chainable {
      login(role?: 'user' | 'admin'): Chainable<void>;
    }
  }
}

Cypress.Commands.add('login', (role = 'user') => {
  cy.session(
    [role, Cypress.config('baseUrl')], // id: role and environment
    () => {
      cy.env([role + '_email', role + '_password']).then((env) => {
        cy.request('POST', '/api/auth/login', {
          email: env[role + '_email'],
          password: env[role + '_password'],
        });
      });
    },
    {
      validate: () => {
        cy.request('/api/me').its('status').should('eq', 200);
      },
    },
  );
});

The test now writes cy.login('admin') and does not know how sign-in works. The session key is an array of the role and baseUrl, so the cache for admin on one environment does not clash with another. When the endpoint changes, the fix is in one place.

Limits and alternatives. A custom command should be short and predictable. If it hides assertions or long scenarios, the test reads worse and a failure points at the command, not at a step. For repeated steps with logic a plain function in a module (the App Actions approach) is often handier because it is typed better and supported by the IDE. The special Cypress.Commands.addQuery is needed only for commands that must retry like queries. Inside cy.origin custom commands are unavailable until they are attached inside the block.

And in Playwright:

The role of a custom command is played there by fixtures: a fixture can hand out an already logged-in user, and storageState keeps the session between tests. Typing comes from TypeScript itself with no global interface extension.

Common mistakes.

  • A session key without a role or environment: different users share a cache and a test gets the wrong session.
  • Not declaring the command in Chainable: JavaScript works but TypeScript flags cy.login as unknown.
  • Putting cy.visit and assertions into the command: every test gets hidden behaviour.
  • Not adding validate: an expired session shows up as a random failure in a test.

Check yourself

The command cy.login(role) calls cy.session('user', …) with a fixed id, and a test calls it with the role admin. What goes wrong?

Answer

All roles share one cache under the id 'user', so admin gets the session of an ordinary user (or the other way round). The id must contain the role: cy.session(role, …).

Why extend Chainable if the JavaScript code works anyway?

Answer

It is needed only by the TypeScript compiler: without the declaration cy.login counts as unknown. The declaration also gives autocompletion and argument type checking.

In an interview. Junior: I add custom commands through Cypress.Commands.add in the support file: they gather repeated actions such as login or data creation in one place. In TypeScript they are declared in Chainable. Middle/Senior: I do the login through the API and wrap it in cy.session, composing the key from the role and the environment so caches do not mix. I keep the command short with no assertions and move more complex logic into functions in modules when better types are needed.

Tabs, iframes, cross-origin

Cypress works in one tab, so it does not open a new tab or window. For tabs the target attribute is removed, or href or a window.open call through a stub is checked, and for a same-origin iframe contentDocument.body is taken and wrapped in cy.wrap. A cross-origin iframe cannot be opened this way because of the same-origin policy, and cy.origin does not help here.

Cypress · Sessions and isolation

A link opens in a new tab and Cypress does not see it. What do you do with tabs and iframes?

The “Terms” button opens a document in a new tab and a payment widget lives in an iframe. The test clicks but nothing happens next or commands do not see the content. Cypress works in one tab and has limits with iframes and other origins. The lesson covers what to do about it without hacks.

How it works and why. A test runs together with the page in one tab, so Cypress does not open or control a new tab or window: commands always go to the test tab. There is no built-in command for an iframe because an iframe is a separate document. Its DOM is reachable through contentDocument if the iframe has the same origin, and for a cross-origin iframe the browser forbids such access (the same-origin policy). So the techniques differ: for tabs you change the link behaviour or check the intent, for iframes you get its body and wrap it in cy.wrap.

Two strategies for a new tab

Do not open a tab

Remove target

The test removes target="_blank" and the link opens in the same tab. It checks that the user reaches the right page.

Neither open nor follow

Check href or window.open

It checks the link address or the window.open call through a stub. The new tab itself is not needed by the test.

Figure 1. Neither needs to control a second tab.

Example: a tab and an iframe.

// 1. open in the same tab
cy.contains('a', 'Terms')
  .invoke('removeAttr', 'target')
  .click();
cy.url().should('include', '/terms');

// 2. or check the address and follow it
cy.contains('a', 'Terms')
  .should('have.attr', 'href')
  .then((href) => cy.visit(href as string));

// 3. window.open: stub and check the intent
cy.window().then((win) => cy.stub(win, 'open').as('open'));
cy.contains('button', 'Terms').click();
cy.get('@open').should('have.been.calledWithMatch', '/terms');

// 4. an iframe of the same origin
cy.get('iframe[data-cy=widget]')
  .its('0.contentDocument.body')
  .should('not.be.empty')
  .then(cy.wrap)
  .find('[data-cy=pay]')
  .click();

The first three variants bypass the new tab: it is not needed for the check. The fourth takes the iframe’s body and should('not.be.empty') first waits for the document to load. Typically this code goes into a custom command so it is not repeated in every test.

Limits and alternatives. A cross-origin iframe is not opened this way. For Chromium browsers there is the chromeWebSecurity: false option, but it turns off the browser’s protection and changes behaviour, so the test no longer resembles real user work. If you need a real scenario in a foreign iframe, that is a limit of Cypress’s architecture: take Playwright or check such a widget separately from its host. For several tabs the official route is the @cypress/puppeteer plugin: its cy.puppeteer() command works only in Chromium browsers and does not retry. A move to another origin in the same tab (for example, SSO) is solved by cy.origin, but it does not work for iframes.

And in Playwright:

A new tab is an event: context.waitForEvent('page') or page.waitForEvent('popup'), and an iframe is reached through page.frameLocator(), including cross-origin ones.

Common mistakes.

  • Clicking a link with target="_blank" and expecting changes on the current page: Cypress stayed in the old tab.
  • Taking contentDocument.body without waiting: the iframe has not loaded yet and body is empty.
  • Turning off chromeWebSecurity “just in case”: the test checks behaviour other than what the user sees.
  • Passing a cross-origin link to cy.visit without cy.origin for the following commands.

Check yourself

A user clicks “Terms” and the page opens in a new tab. What test checks that the link leads to the right address without a second tab?

Answer

Check the attribute: cy.contains('a', 'Terms').should('have.attr', 'href', '/terms') and, if needed, remove target and follow the link. There is no need to control a second tab.

Why does the code with contentDocument.body not work for an iframe from a payment provider on another origin?

Answer

The browser’s same-origin policy does not let a page read the DOM of an iframe from another origin, so contentDocument is unavailable. Cypress does not change that: another approach is needed (a separate widget test, Playwright) or the undesirable chromeWebSecurity: false.

In an interview. Junior: Cypress works in one tab, so new tabs are not opened. The typical solution: remove target="_blank" through invoke('removeAttr', 'target') or check the href. For an iframe you take contentDocument.body and wrap it in cy.wrap. Middle/Senior: I understand this is a limit of the architecture: a cross-origin iframe is not covered by Cypress, several tabs only through the @cypress/puppeteer plugin in Chromium, and cy.origin is only for moving to another origin in the tab. For such scenarios I either check the intent (href, a stub for window.open) or take Playwright.