currently using playwright to test api responses from a button click, but once I establish a page.route(...) for a specific url, that handler can never be overridden by future page.route(...) with the same URLs on that page instance. so for now, in my afterEach, i have this: (is this the right way to have a new route handler override for the same route url?):
page._routes.pop();
await page._delegate.updateRequestInterception();
So my tests currently look like this:
describe('submit info', () => {
let infoBtn;
beforeAll(async () => {
infoBtn = await page.$(infoBtnSelector);
});
afterEach(async () => {
page._routes.pop();
await page._delegate.updateRequestInterception();
});
it('should show error-message when api call fails', async () => {
const handler = sharedUtils.routeHandler(API_URLS.PERSIST_INFO, {status: 504});
await page.route(`${BASE_URL}${API_URLS.PERSIST_INFO}`, handler);
await infoBtn.click();
await page.waitForResponse(`${BASE_URL}${API_URLS.PERSIST_INFO}`);
expect(await sharedUtils.getText(await page.$(ERR_MSG_SELECTOR))).toEqual(VALIDATION_TEXTS.API_ERR);
});
it('should show error-message when api is successful but persist fails', async () => {
const handler = sharedUtils.routeHandler(API_URLS.PERSIST_INFO, {status: 200, body: JSON.stringify({isOperationSuccessful: false})});
await page.route(`${BASE_URL}${API_URLS.PERSIST_INFO}`, handler);
await infoBtn.click();
await page.waitForResponse(`${BASE_URL}${API_URLS.PERSIST_INFO}`);
expect(await sharedUtils.getText(await page.$(ERR_MSG_SELECTOR))).toEqual(VALIDATION_TEXTS.API_ERR);
});
it('should go to finished when persist info succeeds', async () => {
const handler = sharedUtils.routeHandler(API_URLS.PERSIST_INFO, {status: 200, body: JSON.stringify({isOperationSuccessful: true})});
await page.route(`${BASE_URL}${API_URLS.PERSIST_INFO}`, handler);
await infoBtn.click();
await page.waitForNavigation();
expect(page.url()).toContain('finished');
});
});
is there a way for page.route to look for overlapping urls and take the newest handler?
currently using playwright to test api responses from a button click, but once I establish a page.route(...) for a specific url, that handler can never be overridden by future page.route(...) with the same URLs on that page instance. so for now, in my afterEach, i have this: (is this the right way to have a new route handler override for the same route url?):
So my tests currently look like this:
is there a way for page.route to look for overlapping urls and take the newest handler?