question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cypress commands don't work inside an origin block

See original GitHub issue
  • cypress-testing-library version: 7.0.6
  • node version: 14.17.5
  • npm (or yarn) version: 6.14.15
  • Cypress 9.6.1 (9.6.0 min needed for experimental cy.origin function)

Relevant code or config

"experimentalSessionAndOrigin": true,
cy.visit('/')
// works as expected
cy.findByText('foo')

cy.origin('google.com', () => {
  cy.visit('/')
  // will crash with "cy.findByText is not a function"
  cy.findByText('foo')
})

What you did:

  • called cy.findByText within a cy.origin callback

What happened:

  • crashed with “cy.findByText is not a function” error

Capture d’écran 2022-05-17 à 16 36 12

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:9
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
csky-ryangibsoncommented, Aug 24, 2022

This is a known limitation with cy.origin (that custom commands don’t work). There is a workaround I was pointed to by Gleb which is to make another cy.origin block in the beforeEach block. This origin block would be pointed to the same origin that you are trying to use in your main test. You would setup your custom command in this first origin block and you will be able to use it within the origin block in your test. https://docs.cypress.io/api/commands/origin#Callback-restrictions

1reaction
pakhilovcommented, Jul 21, 2022

I have the same problem with cypress-testing-library and real-events

Read more comments on GitHub >

github_iconTop Results From Across the Web

origin - Cypress Documentation
Visit multiple domains of different origin in a single test. In normal use, a single Cypress test may only run commands in a...
Read more >
error when i use cy.xpath inside cy.origin - Stack Overflow
The workaround is to create a custom Cypress command within the secondary origin in a before block: before(() => { cy.origin('somesite.com', ...
Read more >
Fixing Cypress cross-origin errors - Reflect.run
Cypress does not operate outside of the browser runtime, ... domains in a single test via the new cy.origin() command. cy.origin() works by ......
Read more >
Multi-Domain (Origin) Testing in Cypress - DEV Community ‍ ‍
As you can see, we are essentially just removing the code we were doing before inside of our test to the support/commands.js file....
Read more >
Cypress cy.intercept Problems - Gleb Bahmutov
visit command. By the time cy.intercept runs, the call is already in progress, and thus not intercepted. Cypress shows XHR calls by default...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found