Cully
Cully

Reputation: 6975

How do I set the baseUrl in Playwright without using the global config

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?

Upvotes: 1

Views: 1504

Answers (1)

Cully
Cully

Reputation: 6975

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.

Upvotes: 1

Related Questions