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] Set page route abort before all tests start running.

See original GitHub issue

Hi, I want to mock all my HTTP requests and abort them before tests start running. I’ve tried to set that in the global-setup file but looks like the page return in the tests does not contain the routes. I have the solution of beforeAll on every test page, but I want something more general, is it possible?

// global-setup.ts
import { chromium, FullConfig, Route } from "@playwright/test";

async function globalSetup(config: FullConfig) {
  const browser = await chromium.launch();
  const page = await browser.newPage();
  await page.route("**/v1/*/", (route: Route) => {
    route.abort();
  });
}

Thanks!

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
mxschmittcommented, Dec 15, 2021

If you want to have it for all the pages, you can override the page fixture, apply there your overrides and use this “new instance” everywhere. For example:

// foo.fixtures.ts
import { test as base } from '@playwright/test';

export const test = base.extend({
  page: async ({ baseURL, page }, use) => {
    await page.route(....)
    await use(page);
  },
});
import { test } from './test.fixtures';

test(....)

See here for more information: https://playwright.dev/docs/test-fixtures#overriding-fixtures

0reactions
OriAmircommented, Dec 22, 2021

thanks for the response and the help @mxschmitt

Read more comments on GitHub >

github_iconTop Results From Across the Web

Playwright not able to intercept all requests - Stack Overflow
The issue is, that the requests will be made, after the page is fully loaded from the browser perspective. So you have to...
Read more >
How can I stop a route from a route - Apache Camel
Stopping a route during routing an existing message is a bit tricky. The reason for that is Camel will Graceful Shutdown the route...
Read more >
Cypress cy.intercept Problems - Gleb Bahmutov
In our test both intercepts only spied on the request. Now someone comes along and asks why do we need to reset the...
Read more >
Best Practices - Cypress Documentation
Best Practice: Clean up state before tests run. We see many of our users adding code to an after or afterEach hook in...
Read more >
Environments and deployments - GitLab Docs
The job with action: stop might not run if it's in a later stage than the job that started the environment. If you...
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