Home > Software engineering >  How do I set the baseUrl in Playwright without using the global config
How do I set the baseUrl in Playwright without using the global config

Time:12-13

I'm using Playwright to do some task automation. I don't want to use global config (playwright.config.ts). However, I'd still like to use a common baseUrl for all of my tasks. How do I set the baseUrl if I don't have a global config file?

CodePudding user response:

It turns out you can set the baseUrl when creating a context:

const browser = await chromium.launch({
  headless: true,
});

const context = await browser.newContext({
  baseURL: "https://example.com",
});

You'll have to do this individually for every context you create (unlike the baseUrl in the global config). But it works.

  • Related