Cypress commands don't work inside an origin block
See original GitHub issuecypress-testing-library
version: 7.0.6node
version: 14.17.5npm
(oryarn
) 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 acy.origin
callback
What happened:
- crashed with “cy.findByText is not a function” error
Issue Analytics
- State:
- Created a year ago
- Reactions:9
- Comments:13 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
I have the same problem with cypress-testing-library and real-events