I have been using the Cypress testing tool for end to end tests. However, when it comes to saving and displaying certain data, it'll save when done manually but not when the Cypress bot runs through it. You can even do it manually through the Cypress UI and it'll work, just not when run by the tests.
This Error is coming from Cypress:
(xhr)POST 500 <current URL here>
This error is coming up in the console:
Failed to load the resource: the server responded with a status of 500 (Internal Server Error)
Followed by:
AxiosError code: "ERR_BAD_RESPONSE" config: {transitional: {…}, adapter: Array(2), transformRequest: Array(1), transformResponse: Array(1), timeout: 0, …} message: "Request failed with status code 500" name: "AxiosError" request: XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …} response: {data: {…}, status: 500, statusText: 'Internal Server Error', headers: AxiosHeaders, config: {…}, …} stack: "AxiosError: Request failed with status code 500\n at settle (http://localhost:1234/node_modules/.vite/deps/axios.js?v=4b79c220:1189:12)\n at XMLHttpRequest.onloadend (http://localhost:1234/node_modules/.vite/deps/axios.js?v=4b79c220:1417:7)" [[Prototype]] : Error
I am using the Chrome browser, Windows, VSCode as the IDE, and a Bash terminal, if that helps.
I originally thought it was an origin issue, because the data being saved is calculated through Google Maps, but even when the ChromeWebSecurity is false, nothing changes.
I have been opening Cypress with npx cypress open --config chromeWebSecurity=false
, and chromeWebSecurity: false
is in the cypress.config.ts file.
I thought maybe it was local storage between tests which wasn't saving, although it made little to no sense since this all occurs in one e2e test.
Putting cy.saveLocalStorage() when the info is saved and cy.restoreLocalStorage() when it should be displayed, does not help.
I have been Googling for hours. Any ideas are welcome, thanks.
The quick way forward might be to use an intercept and stub the response to POST appropriately.
cy.intercept({
method: 'POST',
url: ...
},
{
// stub response here, check devtools/Network for live response details
})