[Question] Removing routes from page._routes
See original GitHub issuecurrently 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?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Flutter navigation removing in between routes - Stack Overflow
Flutter navigation removing in between routes · Dashboard landing screen. · User clicks on the List Topic button and lands on List of...
Read more >Remove existing routes · Issue #1234 · vuejs/vue-router - GitHub
I give another usage example of deleting/replacing routes. In an app, I use routes to switch pages, all with the same component, changing ......
Read more >How To Handle Routing in React Apps with React Router
In this case, create a keyword of :type . The full path will be /whale/:type . This will match any route that starts...
Read more >Diagnose an Azure virtual machine routing problem
Learn how to diagnose a virtual machine routing problem by viewing the effective routes for a virtual machine.
Read more >Delete Route: Destroying a Resource | Make Parties
So we need a delete action route. After deleting the event, it should redirect to the home page ( events-index ) because the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Leaving this here for reference:
https://github.com/microsoft/playwright/blob/master/docs/api.md#browsercontextunrouteurl-handler
EDIT: Also, when passing RegExp to url, make sure to pass the same object.
THIS WORKS
THIS DOES NOT WORK
This is because
/asdf/ != /asdf/
.There is now wait to unroute.