question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] Removing routes from page._routes

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
aesyonducommented, Sep 25, 2020

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

const myroute = /myroute/
await page.route(myroute, handler)
await page.unroute(myroute)

THIS DOES NOT WORK

await page.route(/myroute/, handler)
await page.unroute(/myroute/) // WRONG

This is because /asdf/ != /asdf/.

2reactions
pavelfeldmancommented, May 26, 2020

There is now wait to unroute.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found