Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
122
rated 0 times [  126] [ 4]  / answers: 1 / hits: 5192  / 4 Years ago, wed, november 11, 2020, 12:00:00

I have a scenario where in I have to process and validate the XHR response of nearly equal URLs:


URL-1: http://localhost:8080/api/customer/123/acounts
URL-2: http://localhost:8080/api/customer/asfgeras-qwe2-34hg-qwerhngfa

when I initialize the server in cypress and mention the xhr url as following, it always returns me the response of the URL-1 (which in my case is called first by the AUT) but I am unable to fetch the response of URL-2 although it is called in the AUT.


cy.server();
cy.route('GET','**/api/customer/**').as('GETCustomer);


I want to capture the response of URL-2.
Please suggest any approach to do so (preferably regEx)


More From » regex

 Answers
2

The above solution works for a wild card search criteria but not for specific api search.
Using something like this can help you sort out the request


cy.route('GET', //api/customer/([a-zA-Z0-9]){8}-([a-zA-Z0-9]){4}-([a-zA-Z0-9]){4}-([a-zA-Z0-9]){4}-([a-zA-Z0-9]){1,}$/).as('GETCustomer');

[#2321] Friday, November 6, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zahrafrancisr

Total Points: 176
Total Questions: 105
Total Answers: 99

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
;