cypress-recurse icon indicating copy to clipboard operation
cypress-recurse copied to clipboard

Is it possible to log response from cy.request() when recursion ends?

Open romankhomitskyi opened this issue 3 years ago • 6 comments

I was wondering if it's possible to log response from cy.request() when recursion ends?

Like { error: response.body }

romankhomitskyi avatar Jan 25 '22 18:01 romankhomitskyi

can you provide the full example of what you are trying to do?

bahmutov avatar Mar 15 '22 10:03 bahmutov

I meant, is it possible to output cypress default error mesage instead of message Recursion hits the limit? By cypress default error messages I mean for example

When we use cy.request in recursion, and when recursion hits the limit, I would like to get message like "The request we sent...." "Response body is ...."

And same for dom commands,

romankhomitskyi avatar Mar 23 '22 16:03 romankhomitskyi

I am not sure what you want the error message to be, can you provide a test and a screenshot of what you want the error to look like?

bahmutov avatar Mar 23 '22 16:03 bahmutov

Instead of error max time limit is reached Screenshot 2022-03-23 at 21 01 19

I would like to have Cypress error image

I mean to get somehow original error from cypress when last iteration is failed

romankhomitskyi avatar Mar 23 '22 19:03 romankhomitskyi

Is the error thrown from the predicate function?

Sent from my iPhone

On Mar 23, 2022, at 15:03, Roman Khomitskyi @.***> wrote:

 Instead of error max time limit is reached

I would like to have Cypress error

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.

bahmutov avatar Mar 23 '22 19:03 bahmutov

const apiRequest = (): Cypress.Chainable<Cypress.Response<any>> => {
		return cy.request({ followRedirect: false, failOnStatusCode: false, ...options });
	};v

const shouldBeAuthorized = (response): boolean => response.status !== 401;

return recurse(apiRequest, shouldBeAuthorized, { post: getNewToken, log: true, limit: 5, delay: 1000 }).then(
		response => {
			if (clientErrors.includes(response.status) || serverErrors.includes(response.status)) {
				throw new Error(
					`Status code ${response.status} Request Headers ${JSON.stringify(
						response.requestHeaders
					)}  Response Body ${JSON.stringify(response.body)} `
				);
			}
			return response;
		}
	);

Here is my use case Instead of my custom Error and error max time limit is reached I would like to get Cypress Error when the last iteration is failed Is it possibe?

romankhomitskyi avatar Mar 24 '22 19:03 romankhomitskyi