0

cy.intercept returns always uppercase body results; how to solve? I am using cy.intercept to get data from an API and compare it with the screen, so it is always returning uppercase values. With that said, my compare code is failing when using cy.get(element).should('contain', apiValue) because we have firstlettercapitalized on screen and uppercase on API.

cy.intercept('GET', '/api-customers/welcome').as('getAPIwelcome')

cy.wait(['@getAPIwelcome']).spread( (getAPI) => { validatePageContents(getAPI); 
}) 

export const validatePageContents = (getAPIwelcome) => { 
let custName = getAPIwelcome.response?.body.firstName 
}

Thanks.

I have this code example and the value from the API when opening the request/response from postman for example has the value “Jonathan” for first name but the object custName has the value "JONATHAN".

I am just trying to understand the reason.

  • Welcome to StackOverflow. The problem you are asking about is not a general one, since `cy.intercept()` does not internally change the case of response characters. As it stands, there is no clue in your question as to why it happens. What details can you add to make the problem solvable? – Aladin Spaz Aug 28 '23 at 19:54
  • Thanks to interact Aladin. I included more details. – Jonathan Oliveira Aug 28 '23 at 23:41
  • Cheers, I forgot to also ask - presume you checked the API response in devtools/Network? – Aladin Spaz Aug 29 '23 at 02:01
  • This is not a cypress issue, or any issue as a matter of fact. What you are seeing in the screen is not what the API returns, it's what frontend decides to do with that. API -> Frontend -> html code in your screen That means that either frontend is applying some formatting to the values that the API returns OR it returns its own values based on the API ones. Without that piece of frontend code I wouldn't be able to advise you how to proceed with what you want to do. – Stratos Ion Aug 30 '23 at 16:34

0 Answers0