Edgaras Karka
Edgaras Karka

Reputation: 7852

Cypress global cy.fixture setup

I am looking way for a way to mock external images by URL. For example, I have a logo that is stored on https://example.com/logo.png. My goal is to load the logo from the fixtures folder instead of creating requests for the logo every test. I expect something like `cy.fixture('https://example.com/logo.png', '/logo.png'). I want to tell cypress to replace all logo requests to fixture.

Upvotes: 2

Views: 826

Answers (1)

Nick
Nick

Reputation: 64

If I got you right, then the below solution will do the trick

If you use a >= 6.0 Cypress version, you can set up a global request listener in the index file in the support folder. It could look something like this:

cy.intercept('GET', 'https://example.com/logo.png', { fixture: 'logo.png' });

See the official Cypress docs on this

Upvotes: 2

Related Questions