Closed domipakmur closed 1 year ago
Hi @domipakmur đź‘‹, thanks for logging this issue. Unfortunately, I wasn't able to recreate the issue with my reproduction project. The cy.intercept
in the beforeEach functioned as expected. If you could please update the project to reproduce the issue that would help me investigate.
I am also facing the same issue when I upgraded the cypress from 10.11.0 to 12.5.1
@sanguinesonal, do you have or can you create a reproduction project that I can use to investigate? Feel free to use my reproduction project as a starting point.
I see that this is not only problem with beforeEach. I also have problem with intercept when I put them between my "IT". This is my intercept:
cy.intercept("POST", "api/calculation/*").as("changeValue");
I see that request went, but cypress didn't see that:
Some intercepts work, but some don't. I don't know what is the reason. Like I said before new version every intercept worked.
@domipakmur, right now there doesn't seem to be enough information to reproduce the problem on our end. Unless we receive a reliable reproduction, we'll eventually have to close this issue until we can reproduce it. This does not mean that your issue is not happening - it just means that we do not have a path to move forward. I provided my reproduction project above, if you could modify it to reproduce the issue I would be happy to look into it.
Unfortunately we have to close this issue due to inactivity. Please comment if there is new information to provide concerning the original issue and we can reopen.
I have identified the problem. In the version after 10.11.0 cypress is reading the cookies differently and thus my post request were failing and get requests were passed. I change the intercepts written and it worked… Definitely not an issue with cypress @domipakmur happy to guide you as well..
@sanguinesonal Would you be able to share what you changed to solve this problem? I am having the same issue.
@alexandersdickinson can you share your code snippet..as for me it was related to how cypress was reading the cookie which was set by my application…
@sanguinesonal I realized that you have problems after cypress 10.11, but I was already on cypress 11, and this problem occurred after upgrading to cypress 12, so my problem may be unrelated. Then again, cypress 12 made some changes regarding test isolation defaults that might affect how cookies are handled. Either way, here is the code snippet:
cy.intercept("POST", endpoint, (req) => {
const queryName = gql`
${req.body.query}
`<some accessors to get query name>;
if (operationNames.includes(queryName)) {
req.alias = queryName;
}
});
This is run to alias graphQL requests so cypress can wait on them. When run in the body of tests, there are no problems. In the beforeEach
, the problem seems to be that req.body
is an empty string, so the query name is not found, and an error is thrown.
@alexandersdickinson yes you are right this is a different problem..not related to mine..
I'm having this error trying to work with the cypress-realworld-testing-blog from learn.cypress.io; in the network-requests.cy.js there's an intercept in the beforeEach and this error is coming up.
Hi @lalicia can you please open an issue in the cypress-realworld-app repo detailing your problem?
Hi @lalicia can you please open an issue in the cypress-realworld-app repo detailing your problem?
Hi @nagash77 - I'm unable to do this as the repo is archived and it won't allow me to open a new issue.
For further clarity I got to the repo by doing the courses on learn.cypress.io - it was linked in the final course I believe.
@lalicia This repository should not be archived (https://github.com/cypress-io/cypress-realworld-app).
cy.intercept("POST", endpoint, (req) => { const queryName = gql` ${req.body.query} `<some accessors to get query name>; if (operationNames.includes(queryName)) { req.alias = queryName; } });
This is run to alias graphQL requests so cypress can wait on them. When run in the body of tests, there are no problems. In the
beforeEach
, the problem seems to be thatreq.body
is an empty string, so the query name is not found, and an error is thrown.
@alexandersdickinson I am experiencing exactly the same issue intermittently when setting up intercepts for GraphQL POST requests in the beforeEach
: sometimes the body is empty. Did you find a solution in the end, or open another issue?
Current behavior
I defined intercept in beforeEach. Running my test the cypress can't see my intercept.
The intercepts work when I add them to every it section.
Desired behavior
Cypress should see the intercept from beforeEach. I migrated my cypress (and all tests) from the 9.7 version to 12.5.1; previously, I didn't have a problem with beforeEach.
Test code to reproduce
same in it:
Cypress Version
v12.5.1
Node version
v16.13.2
Operating System
Windows 10 21H2
Debug Logs
No response
Other
No response