-
Notifications
You must be signed in to change notification settings - Fork 52
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
Uncaught CypressError #5
Comments
@bautistaaa this is unfortunately an expected behaviour. You should only ever see this error when you have a test that calls the same url but expect different response bodies based on different request bodies. This shouldn't be effecting your mocks or tests in any way, though please let me know if it is! Although everything should be working, there's no way I could remove the error that Cypress is showing. Just a little context on what is going on here! A big challenge I ran into while working on this plugin was that Cypress' built in stubbing command TLDR: I had to break some Cypress rules and do some hacky recursion in order for mocking to work for routes with the same URL but different response bodies (I would love any PRs for a better solution to this problem) I do think this error is very confusing for someone using the plugin to encounter and it make sense for me to add a warning in the ReadMe! Thanks for submitting the bug! 😊 I will update the ReadMe before closing out this ticket if these errors are not breaking your tests! |
Great explanation.. super confusing indeed. I'll continue to play around with it although it does skip any test after the point the error occurs. I'll go ahead and close and see if I can help in any way! |
Ahh interesting, let me look into this and get back to you! |
i anticipate its cause im using fetch and I dont delete |
I did my own test to see the behaviour for the CypressError you are encountering and it looks like it is behaving as expected. Although you do see the error, the tests afterwards are not skipped and it has no other effects on the tests or recordings. This is what it looked like for me: All 3 of my tests were producing the CypressError. Could the test be failing/skipping for other reasons? |
As for you second question, it looks like Cypress has some issues with When I tried it in my test app, the fetch requests are not showing up in Cypress and not being recorded. Are you doing anything to get it to work? If you can help me reproduce the empty response error, I will be able to put in a fix for it! |
@Nanciee yep if you look at my original post you'll see this after the record command cy.visit('/login', {
onBeforeLoad(win) {
delete win.fetch;
},
}); This will cause the browser to default to XHR! I do have a custom command to log me in programmatically via a http so maybe thats it. I've been sidetracked a bit =*( but I plan to jump back into this and see if I can contribute in any way |
this is what my test looks like:
I don't have anything else in the beforeEach! As for the blob bug, I'll open a separate bug to deal with all other responseType that isn't JSON. Really appreciate you posting the problem! |
Some changes were published recently that could have fixed the empty response issue you posted about earlier! Could you test this out on v1.0.13? |
no dice! also still seeing the issue where it completely kill the test suite
my beforeEach only has this
however, I am about to swap fetch with axios so that should resolve this I think, will let you know |
Hmm I'm also curious what your custom |
update: moving everything away from fetch fixed the recording issue. heres the full stack trace of the error I get running the test AFTER the initial record
FULL TEST const prefillUserDataAndSubmit = () => {
cy.dataQa('register_name_input').type('Test User', { force: true });
cy.dataQa('register_username_input').type('test2@email.com', { force: true });
cy.dataQa('register_password_input').type('password', { force: true });
cy.dataQa('register_confirm_password_input').type('password', { force: true });
cy.dataQa('btn_create_account').click();
};
context('Register', () => {
autoRecord(__filename);
beforeEach(() => {
cy.visit('/register');
});
it('user can create account successfully', () => {
prefillUserDataAndSubmit();
cy.location('pathname').should('equal', '/');
});
}) Cypress.Commands.add('dataQa', (attr) => {
return cy.get(`[data-qa="${attr}"]`);
}); no references to route on my end I believe |
actually looks like it hates my |
Looks like it comes down to when a single endpoint is hit multiple times.
This caused two size-preferences recording to be entered for a single test, if I remove one of the duplicates it will pass. (any duplicate request I believe) Second Issue is with graphql requests. It recorded the two fine BUT when it goes to retrieve the recorded responses it appears to always pick whichever one shows up first in the list of recordings(I think still digging) I'll see if I can dig into the recursion part that you added since you said that was created to avoid this error but I think one key thing is to not record a request if it has the same body and response? Lmk if you can think of anything! |
This seems to be the same issue mentioned in #9! I published another change (v1.1.0) a few minutes ago which is meant to address this. Everything looks good when I tested it out but would love to hear if it fixes your issue! |
no dice, still errors when two request exist with the same signature in the recording(deleting one will get past it seems at the moment) It doesn't like my graphql requests since I am sending a stringified graphql query. It will always return whichever shows up first in the list it seems. I'll see if I can resolve this and make a PR asap cause its a blocker for me atm! e.g: {
"url": "http://localhost:5100/web-api/graphql",
"method": "POST",
"status": 200,
"headers": {},
"body": {
"query": "{\n viewer {\n collections(limit: 16) {\n slug\n title\n }\n }\n }"
},
"response": {
"data": {
"viewer": {
"collections": []
}
}
}
} {
"url": "http://localhost:5100/web-api/graphql",
"method": "POST",
"status": 200,
"headers": {},
"body": {
"query": "\n {\n viewer {\n currentUser {\n id\n username\n email\n name\n size\n sizeBrand\n sizeGender\n sizeUnit\n braintree_customer_id\n addresses {\n id\n address1\n address2\n validation_failed\n city\n state\n name\n state_code\n postal_code\n country\n country_code\n phone\n address_type\n }\n billing_infos {\n id\n card_brand\n last_4_digits\n affirm_checkout_token\n processor_name\n braintree_payment_method_token\n payment_type\n billing_address {\n id\n address1\n address2\n validation_failed\n city\n state\n name\n state_code\n postal_code\n country\n country_code\n phone\n validation_failed\n }\n }\n }\n }\n }\n "
},
"response": {
"data": {
"viewer": {
"currentUser": null
}
}
}
}, |
PR for duplicate recording #15 |
Thanks!! Are you still having issues with the POST requests? I'm having a really hard time reproducing both of these issues you are having. It shouldn't matter what you are sending in the body since it will mock back the response in order that they were called. Are your graphql requests happening at around the same time? I'm wondering if this is timing related. Since I change the response body in the onResponse hook, it might not have had enough time to switch to the second response body. |
I made a publish for v1.1.1@beta to get you to test out the changes! Let me know if it fixes your issue and I will make a full release. |
Oh let me clarify, when I have duplicate GET requests with the same shape I will get the error screenshotted. My POST requests it also seems to hate {
"url": "http://localhost:5100/rpc/finch/assign",
"method": "POST",
"status": 200,
"headers": {},
"body": {
"user": {
"deviceId": "4819e011-f58c-4919-bc00-076e93d9a792",
"sessionId": "6F05CE45-1A14-478A-A86C-29E0179C5318"
},
"experimentId": {
"name": "styles_trending_web"
}
},
"response": {
"group": {
"name": "control",
"weight": 0.5
}
}
},
{
"url": "http://localhost:5100/rpc/finch/assign",
"method": "POST",
"status": 200,
"headers": {},
"body": {
"user": {
"deviceId": "4819e011-f58c-4919-bc00-076e93d9a792",
"sessionId": "6F05CE45-1A14-478A-A86C-29E0179C5318"
},
"experimentId": {
"name": "recently_viewed_v1"
}
},
"response": {
"group": {
"name": "control",
"weight": 0.5
}
}
} it('user can show/hide nav menu', () => {
cy.visit('/');
cy.dataQa('nav_overlay').should('not.be.visible');
cy.dataQa('hamburger_menu').click();
cy.dataQa('nav_overlay')
.should('be.visible')
.click()
.should('not.be.visible');
}); I'll keep you posted if I ever find a solution but just seems to be a cypress problem stubbing requests with same URL which is weird cause looks like it works for you here #9 but looks like the key difference for me is my status is the same for both looks like I need to go the querystring route =*( |
Yep it works! Have it linked locally as well so I am able to test that way too! |
Same problem here, the library is unable to record the body or the response of the requests. I tried the beta version (1.1.1) and it didn't help. I'm using |
I also may be having the same issue. It fails as soon as it hits a point in which two multiple requests (that return the same payload) occur back to back. However, this is also occurring in my beforeEach. I'd like to try the v1.1.1@beta to see if that helps. How can I access this? @bautistaaa / @Nanciee |
If the url's are the exact same you will need to come up with a way to make those url's unique when stubbing. |
This specific request appears to be triggered by legacy code / duplication. This is fired when the login page is loaded. It isn't a request I am making in my test code. Is there a way to handle this or even skip duplicates? |
We currently have a wrapper around our api calls that allows us to append a querystring in the context of |
Ok gotcha! Do you have an example of this implementation I can take a look at? Trying to wrap my head around it. |
at its most basic form it will look something like this const createCypressUrlOrDefault = (url, intent) => {
if (!url) {
throw Error('Url must be supplied!');
}
if (root.Cypress) {
if (!intent) {
return url;
}
return `${url}?${intent}`;
}
return url;
};
export default createCypressUrlOrDefault; |
Hello! First off thanks for the tool!
I am encountering an error after the initial recording(see image below). I will try to see if I can prevent this somehow and make a PR but maybe you know something off the top of your head!
Here is my test code:
Versions
Error
The text was updated successfully, but these errors were encountered: