0

Below is my code. When the application is served and the tests start it uses the BASE_URL I pass in await page.goto(BASE_URL). I want to use another route for all my requests.

describe("Screenshots - PLAYWRIGHT", () => {
  it("Takes screenshots for multiple browsers", async () => {
    for (const browserType of ["chromium", "firefox", "webkit"]) {
      const browser = await playwright[browserType].launch();
      const context = await browser.newContext();
      const page = await context.newPage();
      await page.goto(BASE_URL);
      await page.waitForLoadState("networkidle");
      await page.screenshot({ path: `screenshots/example-${browserType}.png` });
      await browser.close();
    }
  });
});
potnine
  • 41
  • 7

1 Answers1

0

I am afraid not to understand. If you need to change the URL you might do exactly that. What do you want to route? I am using page.route for blocking purposes for example:

   await page.route(
        re.compile(r"((facebook)|(twitter)|(google))"),
              lambda route: route.fulfill(status=404, content_type="text/plain"))

Of course you could also do a 301 redirect to another URL,

  await page.route("**/*", lambda route: route.fulfill(status= 301, location=NEW_URL)

but to me it seems easier to just change the URL for the page.goto()

HolgT
  • 663
  • 5
  • 18