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

Use fixture as request body shortcut #3387

Open
bahmutov opened this issue Feb 8, 2019 · 12 comments
Open

Use fixture as request body shortcut #3387

bahmutov opened this issue Feb 8, 2019 · 12 comments
Labels
E2E Issue related to end-to-end testing pkg/driver This is due to an issue in the packages/driver directory topic: fixtures Fixture loading and usage type: enhancement Requested enhancement of existing feature

Comments

@bahmutov
Copy link
Contributor

bahmutov commented Feb 8, 2019

It would be nice to be able to load and send a fixture file by name like

it('finds issues mentioned', function () {
   cy.request('/api', 'fx:pr-opened')
})

Currently, have to load fixture and then send

it('finds issues mentioned', function () {
    cy.fixture('pr-opened')
      .then(data => cy.request('/api', data))
})
@cypress-bot cypress-bot bot added the stage: needs information Not enough info to reproduce the issue label Feb 8, 2019
@bahmutov
Copy link
Contributor Author

bahmutov commented Feb 8, 2019

mirror to cy.route('/api', 'fx:response')

@cypress-bot cypress-bot bot added stage: ready for work The issue is reproducible and in scope and removed stage: needs information Not enough info to reproduce the issue labels Feb 11, 2019
@jennifer-shehane jennifer-shehane added pkg/driver This is due to an issue in the packages/driver directory difficulty: 1️⃣ type: enhancement Requested enhancement of existing feature good first issue Good for newcomers labels Feb 11, 2019
@Elshaikh
Copy link

Elshaikh commented Feb 25, 2019

hello all ,
@jennifer-shehane need your help plz , post request failed when load body from fixture json file while sent fine when paste body to the request

it('Validate the header', function () {
  cy.server();
  cy.route( 'fixture/fc_return-1adult-1child.json',`fx:data`)
    .then(data => cy.request(`POST`,`http://email-dev-external-endpoint.com/api/send-as-email`,`fx:data`)) // fx:data
})

@jennifer-shehane
Copy link
Member

Hey @Elshaikh, passing 'fx:data' to cy.request() is not currently supported.

This issue is open as a request for Cypress to support this in the future and has not had any work done on it yet.

@gabbersepp
Copy link
Contributor

gabbersepp commented Dec 5, 2019

I like the idea to pass a fixture directly to the request.
But how could the method signatures look like?

Current:

cy.request(url)
cy.request(url, body)
cy.request(method, url)
cy.request(method, url, body)
cy.request(options)

Possible:

cy.request(url) // does it make sense to provide a fixture to a GET request?
cy.request(url, body) // here we do not need a fixture
cy.request(url, fixture) // if a fixture is provided, ise "POST" as default method?
cy.request(method, url, fixture) // throw if method === GET && fixture is given?
cy.request(method, url, body)
cy.request(options)

@samlucax

This comment has been minimized.

@mylearning1005

This comment has been minimized.

@bahmutov bahmutov added the topic: fixtures Fixture loading and usage label Sep 15, 2020
@ladvish
Copy link

ladvish commented Mar 23, 2022

I am interested in working on this feature.

@ladvish
Copy link

ladvish commented Mar 29, 2022

I tried to add this feature..but i think its not possible. (Please correct me if i am thinking wrong)

Here is the PR - #20800

The error i get is:

Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.

The command that returned the promise was:

cy.request()

The cy command you invoked inside the promise was:
cy.fixture()

@cypress-bot cypress-bot bot added stage: icebox and removed stage: ready for work The issue is reproducible and in scope labels Apr 28, 2022
@AtulKrSharma
Copy link

@bahmutov/ @jennifer-shehane - Any updates on this please? Is that even in plan?

@nagash77 nagash77 added the E2E Issue related to end-to-end testing label May 9, 2023
@Crustum7
Copy link
Contributor

Hello! Can I work on this issue? It seems to be abandoned at the moment. I'm just starting out contributing and I thought it would be a good place to start

@Crustum7
Copy link
Contributor

I'm running into the problem where calling cy.fixture() is not allowed and the test structure does not allow calling Cypress.backend('get:fixture', fixtureName, _.pick(options, 'encoding')) either because the request.cy.js test assumes the first call to .backend is a request and not a fixture. Is there a way to circumvent this in request.cy.js, should I create my own testing setup or is there another way to retrieve the contents of the fixture?

@thevladisss
Copy link
Contributor

@jennifer-shehane Is this issue still active?

@jennifer-shehane jennifer-shehane removed the good first issue Good for newcomers label Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2E Issue related to end-to-end testing pkg/driver This is due to an issue in the packages/driver directory topic: fixtures Fixture loading and usage type: enhancement Requested enhancement of existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.