cypress-testing-library: Cypress commands don't work inside an origin block

  • 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

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 12
  • Comments: 19 (1 by maintainers)

Most upvoted comments

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

@XavierChevalier see https://github.com/cypress-io/cypress/issues/25885 should be fixed with next cypress release (in 4 days)

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

Indeed. Same problem here with cv.findByRole() etc