Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Support external api call to load fixed data in fixture #3066

Open
iamsjn opened this issue Jan 5, 2019 · 2 comments
Open
Labels
pkg/driver This is due to an issue in the packages/driver directory stage: proposal 💡 No work has been done of this issue topic: fixtures Fixture loading and usage type: feature New feature that does not currently exist

Comments

@iamsjn
Copy link

iamsjn commented Jan 5, 2019

Current behavior:

Currently cypress fixture supports loading data from file only located in local drive.

cy.fixture('logo.png').then((logo) => {
  // load data from logo.png
})

Desired behavior:

Fixture should support loading data using external api call-

cy.fixture('https://my-api.com/logo.png').then((logo) => {
  // load data from api
})
@jennifer-shehane
Copy link
Member

I can definitely see the value in this feature and we will other people's interest to determine the development roadmap.

As a workaround today, to use image data from a url location, you can do this.

it('image from request', () => {
  cy
  .request('https://www.cypress.io/img/cypress-io-logo-social-share.png')
  .then((logoResponse) => {
    cy.route('images/*', logoResponse.body).as('getImage')
  })
})

@jennifer-shehane jennifer-shehane added type: feature New feature that does not currently exist pkg/driver This is due to an issue in the packages/driver directory stage: proposal 💡 No work has been done of this issue labels Jan 7, 2019
@eithed
Copy link

eithed commented Sep 5, 2019

Any progress on this? Please consider problems with proposed workaround:

  • you can't do a regex - this becomes very painful when you want to simulate external API returning success/failure for every request - ie: cy.route('GET', ``http://foo.bar.xyz?email=${value-passed-from-form-that-is-inserted-via-faker}``)
  • current workaround does a call to external API - imagine a situation when given image does not exist anymore - expected result would be that tests still pass (because of fixture), not that tests fail because given URL is offline; moreover imagine a scenario where we're making a call to external resource that performs an action - fixture should be used instead of that external call, so that that action isn't performed at all!

A possible solution to this problem is to route your external requests. For example, we're using netlify, which allows to define lambda-functions. As such it's possible to define external url as internal url and thus create fixture; nevertheless, capability to create fixtures in Cypress for external calls would be greatly appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg/driver This is due to an issue in the packages/driver directory stage: proposal 💡 No work has been done of this issue topic: fixtures Fixture loading and usage type: feature New feature that does not currently exist
Projects
None yet
Development

No branches or pull requests

4 participants