← Back to Discord Forum

where to dynamically override PlaywrightTestOptions

leblancmenesesposted in #help-playwright
Open in Discord

I am currently using the approach presented here: https://www.cuketest.com/playwright/docs/test-advanced/#workerinfo-object

While this lets me dynamic spin up hermetic servers and provide a baseURL, it is obtrusive because the developer has to be aware to use the generated baseURL.

test('001', async ({ page, dynamicServerInfo }, testInfo) => {
  await page.goto(`${dynamicServerInfo.baseURL}/#/001`);
  // would prefer await page.goto(`/#/001`);
  await expect(true).toBe(true);

with protractor there were 2 concepts:

  1. onbeforelaunch allowed me to mutate the "Config" (chrome capabilities) before a browser was launched.

  2. onprepare launched the hermetic server - i would override browser.baseUrl which is global scoped variable.

Can someone provide insight to how to achieve #1? https://playwright.dev/docs/test-use-options#configuration-scopes when the value needs to be async'ed resolved.

Can someone provide insight to how to achieve #2?
So the developer writes: await page.goto(`/#/001`); instead of await page.goto(`${dynamicServerInfo.baseURL}/#/001`);

FYI: this would be a good PR for https://playwright.dev/docs/protractor - migration guide. I found the docs around https://playwright.dev/docs/test-global-setup-teardown to be lacking as it doesn't address needs like #1.

This thread is trying to answer question "How to dynamically override PlaywrightTestOptions to achieve cleaner syntax for page navigation?"

2 replies

Hi, you can override the baseURL fixture, make it depend on dynamicServerInfo. https://playwright.dev/docs/test-fixtures#overriding-fixtures

(Untested) sample:

baseURL: async ({ dynamicServerInfo }, use) => {
    await use(dynamicServerInfo.baseURL);

verified this does work. Thank you!

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.